mirror of https://github.com/databricks/cli.git
Clean up unused code (#1502)
## Changes 1. Removes `DefaultMutatorsForTarget` which is no longer used anywhere 2. Makes SnapshotPath a private field. It's no longer needed by data structures outside its package. FYI, I also tried finding other instances of dead code but I could not find anything else that was safe to remove. I used https://go.dev/blog/deadcode to search for them, and the other instances either implemented an interface, increased test coverage for some of our other code paths or there was some other reason I could not remove them (like autogenerated functions or used in tests). Good sign our codebase is mostly clean (at least superficially).
This commit is contained in:
parent
533d357a71
commit
274688d8a2
|
@ -26,10 +26,3 @@ func DefaultMutators() []bundle.Mutator {
|
|||
LoadGitDetails(),
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultMutatorsForTarget(target string) []bundle.Mutator {
|
||||
return append(
|
||||
DefaultMutators(),
|
||||
SelectTarget(target),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ const LatestSnapshotVersion = "v1"
|
|||
type Snapshot struct {
|
||||
// Path where this snapshot was loaded from and will be saved to.
|
||||
// Intentionally not part of the snapshot state because it may be moved by the user.
|
||||
SnapshotPath string `json:"-"`
|
||||
snapshotPath string
|
||||
|
||||
// New indicates if this is a fresh snapshot or if it was loaded from disk.
|
||||
New bool `json:"-"`
|
||||
|
@ -70,7 +70,7 @@ func NewSnapshot(localFiles []fileset.File, opts *SyncOptions) (*Snapshot, error
|
|||
snapshotState.ResetLastModifiedTimes()
|
||||
|
||||
return &Snapshot{
|
||||
SnapshotPath: snapshotPath,
|
||||
snapshotPath: snapshotPath,
|
||||
New: true,
|
||||
Version: LatestSnapshotVersion,
|
||||
Host: opts.Host,
|
||||
|
@ -107,7 +107,7 @@ func newSnapshot(ctx context.Context, opts *SyncOptions) (*Snapshot, error) {
|
|||
}
|
||||
|
||||
return &Snapshot{
|
||||
SnapshotPath: path,
|
||||
snapshotPath: path,
|
||||
New: true,
|
||||
|
||||
Version: LatestSnapshotVersion,
|
||||
|
@ -122,7 +122,7 @@ func newSnapshot(ctx context.Context, opts *SyncOptions) (*Snapshot, error) {
|
|||
}
|
||||
|
||||
func (s *Snapshot) Save(ctx context.Context) error {
|
||||
f, err := os.OpenFile(s.SnapshotPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
f, err := os.OpenFile(s.snapshotPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create/open persisted sync snapshot file: %s", err)
|
||||
}
|
||||
|
@ -147,11 +147,11 @@ func loadOrNewSnapshot(ctx context.Context, opts *SyncOptions) (*Snapshot, error
|
|||
}
|
||||
|
||||
// Snapshot file not found. We return the new copy.
|
||||
if _, err := os.Stat(snapshot.SnapshotPath); errors.Is(err, fs.ErrNotExist) {
|
||||
if _, err := os.Stat(snapshot.snapshotPath); errors.Is(err, fs.ErrNotExist) {
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile(snapshot.SnapshotPath)
|
||||
bytes, err := os.ReadFile(snapshot.snapshotPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read sync snapshot from disk: %s", err)
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ func (s *Snapshot) diff(ctx context.Context, all []fileset.File) (diff, error) {
|
|||
|
||||
currentState := s.SnapshotState
|
||||
if err := currentState.validate(); err != nil {
|
||||
return diff{}, fmt.Errorf("error parsing existing sync state. Please delete your existing sync snapshot file (%s) and retry: %w", s.SnapshotPath, err)
|
||||
return diff{}, fmt.Errorf("error parsing existing sync state. Please delete your existing sync snapshot file (%s) and retry: %w", s.snapshotPath, err)
|
||||
}
|
||||
|
||||
// Compute diff to apply to get from current state to new target state.
|
||||
|
|
|
@ -223,10 +223,6 @@ func (s *Sync) GetFileList(ctx context.Context) ([]fileset.File, error) {
|
|||
return all.Iter(), nil
|
||||
}
|
||||
|
||||
func (s *Sync) SnapshotPath() string {
|
||||
return s.snapshot.SnapshotPath
|
||||
}
|
||||
|
||||
func (s *Sync) RunContinuous(ctx context.Context) error {
|
||||
ticker := time.NewTicker(s.PollInterval)
|
||||
defer ticker.Stop()
|
||||
|
|
Loading…
Reference in New Issue