Skip to content

Commit 14d2b82

Browse files
authored
feat(local): move deleted files to corresponding locations (#1281)
1 parent cdc069d commit 14d2b82

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/local/driver.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,26 @@ func (d *Local) Remove(ctx context.Context, obj model.Obj) error {
375375
err = os.Remove(obj.GetPath())
376376
}
377377
} else {
378-
if !utils.Exists(d.RecycleBinPath) {
379-
err = os.MkdirAll(d.RecycleBinPath, 0o755)
378+
objPath := obj.GetPath()
379+
objName := obj.GetName()
380+
var relPath string
381+
relPath, err = filepath.Rel(d.GetRootPath(), filepath.Dir(objPath))
382+
if err != nil {
383+
return err
384+
}
385+
recycleBinPath := filepath.Join(d.RecycleBinPath, relPath)
386+
if !utils.Exists(recycleBinPath) {
387+
err = os.MkdirAll(recycleBinPath, 0o755)
380388
if err != nil {
381389
return err
382390
}
383391
}
384392

385-
dstPath := filepath.Join(d.RecycleBinPath, obj.GetName())
393+
dstPath := filepath.Join(recycleBinPath, objName)
386394
if utils.Exists(dstPath) {
387-
dstPath = filepath.Join(d.RecycleBinPath, obj.GetName()+"_"+time.Now().Format("20060102150405"))
395+
dstPath = filepath.Join(recycleBinPath, objName+"_"+time.Now().Format("20060102150405"))
388396
}
389-
err = os.Rename(obj.GetPath(), dstPath)
397+
err = os.Rename(objPath, dstPath)
390398
}
391399
if err != nil {
392400
return err

0 commit comments

Comments
 (0)