Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
f674f249a3
2 changed files with 26 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue