From fb56b27062ea2edd0b60decde0c55364b70aa62a Mon Sep 17 00:00:00 2001 From: vvisionnn <0xEFEFEF@gmail.com> Date: Mon, 9 May 2022 19:24:40 +0800 Subject: [PATCH] fix: delete socket file before run (fixed #1262) (#1279) * fix: delete socket file before run (fixed #1262) * refactor: remove useless logs --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index ed7a409..815612e 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "flag" "io" "io/fs" + "os" "strings" "github.com/cloudreve/Cloudreve/v3/bootstrap" @@ -67,6 +68,14 @@ func main() { // 如果启用了Unix if conf.UnixConfig.Listen != "" { + // delete socket file before listening + if _, err := os.Stat(conf.UnixConfig.Listen); err == nil { + if err = os.Remove(conf.UnixConfig.Listen); err != nil { + util.Log().Error("删除 socket 文件错误, %s", err) + return + } + } + util.Log().Info("开始监听 %s", conf.UnixConfig.Listen) if err := api.RunUnix(conf.UnixConfig.Listen); err != nil { util.Log().Error("无法监听[%s],%s", conf.UnixConfig.Listen, err)