feat(local): allow specifying the recycle bin path (close #5832)

pull/5848/head
Andy Hsu 2024-01-09 18:51:21 +08:00
parent 434892f135
commit 34b73b94f7
2 changed files with 12 additions and 3 deletions

View File

@ -257,11 +257,19 @@ 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 utils.SliceContains([]string{"", "delete permanently"}, d.RecycleBinPath) {
if obj.IsDir() {
err = os.RemoveAll(obj.GetPath())
} else {
err = os.Remove(obj.GetPath())
}
} else {
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
}

View File

@ -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{