From 46f01032b81fa8615b8edd06a7eec6e932e821b9 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 15 Mar 2024 16:40:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=9B=9E=E6=94=B6?= =?UTF-8?q?=E7=AB=99=E6=96=87=E4=BB=B6=E6=94=BE=E7=BD=AE=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#4203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/4199 --- backend/app/service/recycle_bin.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/backend/app/service/recycle_bin.go b/backend/app/service/recycle_bin.go index f1d880cd5..02ce52106 100644 --- a/backend/app/service/recycle_bin.go +++ b/backend/app/service/recycle_bin.go @@ -153,22 +153,20 @@ func (r RecycleBinService) Clear() error { } func getClashDir(realPath string) (string, error) { - trimmedPath := strings.Trim(realPath, "/") - parts := strings.Split(trimmedPath, "/") - dir := "" - if len(parts) > 0 { - dir = parts[0] - partitions, err := disk.Partitions(false) - if err != nil { - return "", err + partitions, err := disk.Partitions(false) + if err != nil { + return "", err + } + for _, p := range partitions { + if p.Mountpoint == "/" { + continue } - for _, p := range partitions { - if p.Mountpoint == dir { - if err = createClashDir(path.Join(p.Mountpoint, ".1panel_clash")); err != nil { - return "", err - } - return dir, nil + if strings.HasPrefix(realPath, p.Mountpoint) { + clashDir := path.Join(p.Mountpoint, ".1panel_clash") + if err = createClashDir(path.Join(p.Mountpoint, ".1panel_clash")); err != nil { + return "", err } + return clashDir, nil } } return constant.RecycleBinDir, createClashDir(constant.RecycleBinDir)