Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 改进 `工作空间列表` https://github.com/siyuan-note/siyuan/issues/7067

Liang Ding99261db73a63
diff --git a/kernel/api/workspace.go b/kernel/api/workspace.go
index be62245a83..6b07968c7f 100644
--- a/kernel/api/workspace.go
+++ b/kernel/api/workspace.go
@@ -27,7 +27,7 @@ import (
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
- "github.com/gofrs/flock"
+ "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
)
@@ -89,6 +89,11 @@ func removeWorkspaceDir(c *gin.Context) {
path := arg["path"].(string)
+ if util.IsWorkspaceLocked(path) {
+ logging.LogWarnf("skip remove workspace [%s] because it is locked", path)
+ return
+ }
+
workspacePaths, err := util.ReadWorkspacePaths()
if nil != err {
ret.Code = -1
@@ -127,14 +132,7 @@ func getWorkspaces(c *gin.Context) {
var workspaces []*Workspace
for _, p := range workspacePaths {
- closed := false
- f := flock.New(filepath.Join(p, ".lock"))
- ok, _ := f.TryLock()
- if ok {
- closed = true
- }
- f.Unlock()
-
+ closed := !util.IsWorkspaceLocked(p)
workspaces = append(workspaces, &Workspace{Path: p, Closed: closed})
}
ret.Data = workspaces
diff --git a/kernel/util/working.go b/kernel/util/working.go
index 2b8270bf24..d0136e2792 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -495,6 +495,25 @@ func tryLockWorkspace() {
os.Exit(ExitCodeWorkspaceLocked)
}
+func IsWorkspaceLocked(workspacePath string) bool {
+ if !gulu.File.IsDir(workspacePath) {
+ return false
+ }
+
+ lockFilePath := filepath.Join(workspacePath, ".lock")
+ if !gulu.File.IsExist(lockFilePath) {
+ return false
+ }
+
+ f := flock.New(lockFilePath)
+ defer f.Unlock()
+ ok, _ := f.TryLock()
+ if ok {
+ return false
+ }
+ return true
+}
+
func UnlockWorkspace() {
if nil == WorkspaceLock {
return