fix: harden log directory creation and path resolution
All checks were successful
check-and-test / check-and-test (pull_request) Successful in 1m13s
check-and-test / Run govulncheck (pull_request) Successful in 1m16s

- Ensure the log directory is created with secure permissions, falling back to the temp directory if creation fails - Update log file path to use the resolved log directory fix #58 Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
2025-06-13 17:36:37 +08:00
parent 52ccf92761
commit 5de6d90e25

View File

@@ -32,8 +32,14 @@ func Default() *zap.Logger {
home = os.TempDir()
}
logDir := fmt.Sprintf("%s/.gitea-mcp", home)
if err := os.MkdirAll(logDir, 0o700); err != nil {
// Fallback to temp directory if creation fails
logDir = os.TempDir()
}
wss = append(wss, zapcore.AddSync(&lumberjack.Logger{
Filename: fmt.Sprintf("%s/.gitea-mcp/gitea-mcp.log", home),
Filename: fmt.Sprintf("%s/gitea-mcp.log", logDir),
MaxSize: 100,
MaxBackups: 10,
MaxAge: 30,