From bcda2f45dffc66dc138b160c5a8c4d30f65f574c Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Tue, 9 Jan 2024 18:51:21 +0800 Subject: [PATCH] feat(local): allow specifying the recycle bin path (close #5832) --- drivers/local/driver.go | 14 +++++++++++--- drivers/local/meta.go | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/local/driver.go b/drivers/local/driver.go index ffe1c75ea87d..e1406f905e14 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -256,10 +256,18 @@ func (d *Local) Copy(ctx context.Context, srcObj, dstDir model.Obj) error { func (d *Local) Remove(ctx context.Context, obj model.Obj) error { var err error - if obj.IsDir() { - err = os.RemoveAll(obj.GetPath()) + if utils.SliceContains([]string{"", "delete permanently"}, d.RecycleBinPath) { + if obj.IsDir() { + err = os.RemoveAll(obj.GetPath()) + } else { + err = os.Remove(obj.GetPath()) + } } else { - err = os.Remove(obj.GetPath()) + dstPath := filepath.Join(d.RecycleBinPath, obj.GetName()) + if utils.Exists(dstPath) { + dstPath = filepath.Join(d.RecycleBinPath, obj.GetName()+"_"+time.Now().Format("20060102150405")) + } + err = os.Rename(obj.GetPath(), dstPath) } if err != nil { return err diff --git a/drivers/local/meta.go b/drivers/local/meta.go index 00c8f5ce8b14..51b49e64ef4c 100644 --- a/drivers/local/meta.go +++ b/drivers/local/meta.go @@ -11,6 +11,7 @@ type Addition struct { ThumbCacheFolder string `json:"thumb_cache_folder"` ShowHidden bool `json:"show_hidden" default:"true" required:"false" help:"show hidden directories and files"` MkdirPerm string `json:"mkdir_perm" default:"777"` + RecycleBinPath string `json:"recycle_bin_path" default:"delete permanently" help:"path to recycle bin, delete permanently if empty or keep 'delete permanently'"` } var config = driver.Config{