bb94cf40847a153ae5b703efebb69e676aef3b58

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

Ignore missing file error when deleting downloads

Diff

 1diff --git a/Makefile b/Makefile
 2index 99bd2ce4416e08c4141fd8cbe33ecbb8c8907e0c..fbe57c00e75b42244bfbbcef3a4bbbe730b606d4 100644
 3--- a/Makefile
 4+++ b/Makefile
 5@@ -15,11 +15,15 @@ bin/air: bin
 6 bin/templ: bin
 7 	GOBIN=$(PWD)/bin go install github.com/a-h/templ/cmd/templ@v0.3.1001
 8 
 9-lint: bin/golangci-lint
10+fmt:
11 	go mod tidy
12+	bin/golangci-lint fmt
13+
14+lint: bin/golangci-lint
15+	go mod tidy -diff
16 	go vet ./...
17-	bin/golangci-lint -c .golangci.yml run ./...
18-	bin/golangci-lint -c .golangci.yml fmt ./...
19+	bin/golangci-lint run
20+	bin/golangci-lint fmt -d
21 
22 test:
23 	go test -timeout=30s -race ./...
24diff --git a/handler/cleanup.go b/handler/cleanup.go
25index 98aaa1f54d83c1a5ca07520c03e412e574858d6e..5746d63fcd14f258be7a5fcbc48d0d4dab2a076b 100644
26--- a/handler/cleanup.go
27+++ b/handler/cleanup.go
28@@ -2,6 +2,7 @@ package handler
29 
30 import (
31 	"context"
32+	"errors"
33 	"os"
34 	"time"
35 )
36@@ -37,9 +38,13 @@ func (h *handler) performCleanup(ctx context.Context) {
37 
38 		h.log.Info("Cleaning up video file", "video_id", video.ID, "path", *video.FilePath)
39 
40-		if err := os.Remove(*video.FilePath); err != nil {
41-			h.log.Error("Failed to delete file", "path", *video.FilePath, "error", err)
42-			continue
43+		err := os.Remove(*video.FilePath)
44+		if err != nil {
45+			if !errors.Is(err, os.ErrNotExist) {
46+				h.log.Error("Failed to delete file", "path", *video.FilePath, "error", err)
47+				continue
48+			}
49+			h.log.Warn("File already deleted, cleaning DB entry", "path", *video.FilePath)
50 		}
51 
52 		if err := h.db.DeleteVideoFile(ctx, video.ID); err != nil {