From d7577ffb61c73f5cda2a3d4f8eb7bbac3291f8d1 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 14 Jan 2023 11:26:24 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E5=A4=9A=E4=B8=AA=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E7=AB=AF=E5=BF=AB=E6=8D=B7=E6=96=B9=E5=BC=8F=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E7=9A=84=20`--workspace`=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=90=8E=E6=97=A0=E6=B3=95=E5=90=AF=E5=8A=A8=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/7059?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/util/working.go | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/kernel/util/working.go b/kernel/util/working.go index d0136e279..f49a8accc 100644 --- a/kernel/util/working.go +++ b/kernel/util/working.go @@ -212,36 +212,26 @@ func initWorkspaceDir(workspaceArg string) { if "" != workspaceArg { WorkspaceDir = workspaceArg } - if !gulu.File.IsDir(WorkspaceDir) { - log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", defaultWorkspaceDir, WorkspaceDir) - WorkspaceDir = defaultWorkspaceDir - } - workspacePaths = append(workspacePaths, WorkspaceDir) } else { workspacePaths, _ = ReadWorkspacePaths() if 0 < len(workspacePaths) { + // 取最后一个(也就是最近打开的)工作空间 WorkspaceDir = workspacePaths[len(workspacePaths)-1] - if "" != workspaceArg { - WorkspaceDir = workspaceArg - } - if !gulu.File.IsDir(WorkspaceDir) { - log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir) - WorkspaceDir = defaultWorkspaceDir - } - workspacePaths[len(workspacePaths)-1] = WorkspaceDir } else { WorkspaceDir = defaultWorkspaceDir - if "" != workspaceArg { - WorkspaceDir = workspaceArg - } - if !gulu.File.IsDir(WorkspaceDir) { - log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir) - WorkspaceDir = defaultWorkspaceDir - } - workspacePaths = append(workspacePaths, WorkspaceDir) + } + + if "" != workspaceArg { + WorkspaceDir = workspaceArg } } + if !gulu.File.IsDir(WorkspaceDir) { + log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir) + WorkspaceDir = defaultWorkspaceDir + } + workspacePaths = append(workspacePaths, WorkspaceDir) + if err := WriteWorkspacePaths(workspacePaths); nil != err { log.Fatalf("write workspace conf [%s] failed: %s", workspaceConf, err) } @@ -284,8 +274,6 @@ func ReadWorkspacePaths() (ret []string, err error) { return } - ret = gulu.Str.RemoveDuplicatedElem(ret) - var tmp []string for _, d := range ret { d = strings.TrimRight(d, " \t\n") // 去掉工作空间路径尾部空格 https://github.com/siyuan-note/siyuan/issues/6353 @@ -294,6 +282,7 @@ func ReadWorkspacePaths() (ret []string, err error) { } } ret = tmp + ret = gulu.Str.RemoveDuplicatedElem(ret) return }