Skip to content

Commit

Permalink
don't delete target dir if files: are listed
Browse files Browse the repository at this point in the history
  • Loading branch information
Silas Gyger committed Jan 9, 2024
1 parent 6e36207 commit bb263ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/read_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (conf *copierConf) ToCopierOptions() (*copier.CopyConfig, error) {
}
return includeRegexp.MatchString(path) && !excludeRegexp.MatchString(path)
},
Options: conf.Options,
Options: conf.Options,
ClearTarget: len(files) == 0,
}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/copier/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ type CopyConfig struct {
Options map[string]string
// TempDir contains the path to write all files.
TempDir string
// ClearTarget is true if the target directory should be cleared before copying
ClearTarget bool
}
6 changes: 5 additions & 1 deletion pkg/pasta/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ func Run(ctx context.Context, deps []Dependency, dryRun, keepDirs bool, pastaFil
}

if !dryRun && !keepDirs {
// remove all target directories
// remove target directories if enabled
for _, dep := range deps {
if !dep.Option.ClearTarget {
continue
}

if err := os.RemoveAll(dep.Target); err != nil {
return fmt.Errorf("error removing target directory %v: %v", dep.Target, err)
}
Expand Down

0 comments on commit bb263ce

Please sign in to comment.