Skip to content

Commit

Permalink
feat(local): allow specifying the recycle bin path (close #5832)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jan 9, 2024
1 parent 434892f commit 34b73b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/local/driver.go
Expand Up @@ -257,10 +257,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
Expand Down
1 change: 1 addition & 0 deletions drivers/local/meta.go
Expand Up @@ -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{
Expand Down

0 comments on commit 34b73b9

Please sign in to comment.