Fix renaming to correctly create the base files if missing

This commit is contained in:
Dane Everitt
2020-07-11 16:19:51 -07:00
parent d60b2d6163
commit 233cefd129
2 changed files with 16 additions and 0 deletions

View File

@@ -385,6 +385,20 @@ func (fs *Filesystem) Rename(from string, to string) error {
return errors.WithStack(err)
}
if f, err := os.Stat(cleanedFrom); err != nil {
return errors.WithStack(err)
} else {
d := cleanedTo
if !f.IsDir() {
d = strings.TrimSuffix(d, path.Base(cleanedTo))
}
// Ensure that the directory we're moving into exists correctly on the system.
if mkerr := os.MkdirAll(d, 0644); mkerr != nil {
return errors.WithStack(mkerr)
}
}
return os.Rename(cleanedFrom, cleanedTo)
}