fix(logs): ignore ENOENT when truncating default log file

This commit is contained in:
hkfires
2025-10-16 12:35:29 +08:00
parent 72cb2689e8
commit df3b00621a

View File

@@ -116,7 +116,7 @@ func (h *Handler) DeleteLogs(c *gin.Context) {
name := entry.Name()
fullPath := filepath.Join(dir, name)
if name == defaultLogFileName {
if errTrunc := os.Truncate(fullPath, 0); errTrunc != nil {
if errTrunc := os.Truncate(fullPath, 0); errTrunc != nil && !os.IsNotExist(errTrunc) {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("failed to truncate log file: %v", errTrunc)})
return
}