From f988805c93264f4c88fe6f7244e4193f3cd233bf Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 31 Oct 2022 22:42:30 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=A0=91=E6=8B=96=E6=8B=BD=E5=BD=A2=E6=88=90=E5=AD=90=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=97=B6=E7=9A=84=E5=B1=82=E7=BA=A7=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/6434?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/file.go | 11 ++++++----- kernel/util/path.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index eb18bf34c..efcaebf70 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -992,11 +992,6 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e return } - if depth := strings.Count(toPath, "/"); 6 < depth && !Conf.FileTree.AllowCreateDeeper { - err = errors.New(Conf.Language(118)) - return - } - fromDir := strings.TrimSuffix(fromPath, ".sy") if strings.HasPrefix(toPath, fromDir) { err = errors.New(Conf.Language(87)) @@ -1016,6 +1011,12 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e return } + childDepth := util.GetChildDocDepth(filepath.Join(util.DataDir, fromBoxID, fromPath)) + if depth := strings.Count(toPath, "/") + childDepth; 6 < depth && !Conf.FileTree.AllowCreateDeeper { + err = errors.New(Conf.Language(118)) + return + } + toBox := Conf.Box(toBoxID) if nil == toBox { err = errors.New(Conf.Language(0)) diff --git a/kernel/util/path.go b/kernel/util/path.go index f630f7a81..26be07a28 100644 --- a/kernel/util/path.go +++ b/kernel/util/path.go @@ -21,6 +21,7 @@ import ( "net" "os" "path" + "path/filepath" "strings" "time" @@ -138,3 +139,23 @@ func TimeFromID(id string) (ret string) { ret = id[:14] return } + +func GetChildDocDepth(treeAbsPath string) (ret int) { + dir := strings.TrimSuffix(treeAbsPath, ".sy") + if !gulu.File.IsDir(dir) { + return + } + + baseDepth := strings.Count(filepath.ToSlash(treeAbsPath), "/") + depth := 1 + filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + p := filepath.ToSlash(path) + currentDepth := strings.Count(p, "/") + if depth < currentDepth { + depth = currentDepth + } + return nil + }) + ret = depth - baseDepth + return +}