mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🐛 macOS 端报错 数据库被锁定 Fix https://github.com/siyuan-note/siyuan/issues/6492
This commit is contained in:
parent
2fa409c2e9
commit
51a0db5822
2 changed files with 96 additions and 66 deletions
|
|
@ -32,7 +32,6 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
figure "github.com/common-nighthawk/go-figure"
|
||||
goPS "github.com/mitchellh/go-ps"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
|
@ -347,71 +346,6 @@ func initMime() {
|
|||
mime.AddExtensionType(".pdf", "application/pdf")
|
||||
}
|
||||
|
||||
func KillByPort(port string) {
|
||||
if pid := PidByPort(port); "" != pid {
|
||||
pidInt, _ := strconv.Atoi(pid)
|
||||
proc, _ := goPS.FindProcess(pidInt)
|
||||
var name string
|
||||
if nil != proc {
|
||||
name = proc.Executable()
|
||||
}
|
||||
Kill(pid)
|
||||
logging.LogInfof("killed process [name=%s, pid=%s]", name, pid)
|
||||
}
|
||||
}
|
||||
|
||||
func Kill(pid string) {
|
||||
var kill *exec.Cmd
|
||||
if gulu.OS.IsWindows() {
|
||||
kill = exec.Command("cmd", "/c", "TASKKILL /F /PID "+pid)
|
||||
} else {
|
||||
kill = exec.Command("kill", "-9", pid)
|
||||
}
|
||||
gulu.CmdAttr(kill)
|
||||
kill.CombinedOutput()
|
||||
}
|
||||
|
||||
func PidByPort(port string) (ret string) {
|
||||
if gulu.OS.IsWindows() {
|
||||
cmd := exec.Command("cmd", "/c", "netstat -ano | findstr "+port)
|
||||
gulu.CmdAttr(cmd)
|
||||
data, err := cmd.CombinedOutput()
|
||||
if nil != err {
|
||||
logging.LogErrorf("netstat failed: %s", err)
|
||||
return
|
||||
}
|
||||
output := string(data)
|
||||
lines := strings.Split(output, "\n")
|
||||
for _, l := range lines {
|
||||
if strings.Contains(l, "LISTENING") {
|
||||
l = l[strings.Index(l, "LISTENING")+len("LISTENING"):]
|
||||
l = strings.TrimSpace(l)
|
||||
ret = l
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
cmd := exec.Command("lsof", "-Fp", "-i", ":"+port)
|
||||
gulu.CmdAttr(cmd)
|
||||
data, err := cmd.CombinedOutput()
|
||||
if nil != err {
|
||||
logging.LogErrorf("lsof failed: %s", err)
|
||||
return
|
||||
}
|
||||
output := string(data)
|
||||
lines := strings.Split(output, "\n")
|
||||
for _, l := range lines {
|
||||
if strings.HasPrefix(l, "p") {
|
||||
l = l[1:]
|
||||
ret = l
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func initPandoc() {
|
||||
if ContainerStd != Container {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue