1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-09-15 18:56:59 +00:00

fix: clean up log files that no longer exist

- If for some reason a action log file does not longer exist in the
database or on the file system, then mark it as being cleaned up.
- Unit test added.
This commit is contained in:
Gusted 2024-12-03 05:00:50 +01:00
parent fe246cc060
commit 4e8677a911
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 34 additions and 1 deletions

View file

@ -5,7 +5,9 @@ package actions
import (
"context"
"errors"
"fmt"
"os"
"time"
actions_model "code.gitea.io/gitea/models/actions"
@ -101,7 +103,7 @@ func CleanupLogs(ctx context.Context) error {
return fmt.Errorf("find old tasks: %w", err)
}
for _, task := range tasks {
if err := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename); err != nil {
if err := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename); err != nil && !errors.Is(err, os.ErrNotExist) {
log.Error("Failed to remove log %s (in storage %v) of task %v: %v", task.LogFilename, task.LogInStorage, task.ID, err)
// do not return error here, continue to next task
continue