File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ func (fm *FileManager) ValidateDestDir() error {
15
15
dstInfo , err := os .Stat (fm .DestDir )
16
16
if err != nil {
17
17
if os .IsNotExist (err ) {
18
- return os .MkdirAll (fm .DestDir , 0755 )
18
+ // if destination does not exist, skip validation since the given
19
+ // destination will be created in `fm.MoveFiles`. if created here,
20
+ // `os.Rename` operation will fail due to an existing newpath
21
+ return nil
19
22
}
20
23
return err
21
24
}
@@ -40,7 +43,11 @@ func (fm *FileManager) MoveFiles(sources []string, tempDir string) error {
40
43
dst := filepath .Join (fm .DestDir , ford )
41
44
if err := os .Rename (src , dst ); err != nil {
42
45
if errors .Is (err , os .ErrExist ) {
43
- // overwrite (delete) existing directory here
46
+ // if options.Force:
47
+ // — delete existing directory dst
48
+ // - return nil to continue with overwrite
49
+ // else:
50
+ return fmt .Errorf ("directory with content at `%s' would be overwritten, skipping…" , dst )
44
51
}
45
52
return err
46
53
}
You can’t perform that action at this time.
0 commit comments