restore creates directories if necessary

This commit is contained in:
Lilian Jónsdóttir 2024-07-15 15:59:40 -07:00
parent 26f5f383ce
commit 746bff694c

View file

@ -132,15 +132,26 @@ func Restore(files Files) (restored int, err error) {
if _, e := os.Stat(outpath); e == nil { if _, e := os.Stat(outpath); e == nil {
outpath, cancel = promptNewPath(outpath) outpath, cancel = promptNewPath(outpath)
} }
if cancel { if cancel {
continue continue
} }
basedir := filepath.Dir(outpath)
if _, e := os.Stat(basedir); e != nil {
if err = os.MkdirAll(basedir, fs.FileMode(0755)); err != nil {
return restored, err
}
}
if err = os.Rename(file.path, outpath); err != nil { if err = os.Rename(file.path, outpath); err != nil {
return restored, err return restored, err
} }
if err = os.Remove(file.trashinfo); err != nil { if err = os.Remove(file.trashinfo); err != nil {
return restored, err return restored, err
} }
restored++ restored++
} }
return restored, err return restored, err