Better workaround for Go 1.20 missing context.WithoutCancel

This commit is contained in:
Deluan
2023-12-16 13:33:03 -05:00
parent d3f6b4692d
commit 0e3175ea17
3 changed files with 25 additions and 47 deletions
+2 -24
View File
@@ -4,30 +4,8 @@ package scanner
import (
"context"
"github.com/navidrome/navidrome/core"
"github.com/navidrome/navidrome/log"
)
// TODO: Move this to scanner/scanner.go when we drop support for go 1.20
func (s *scanner) RescanAll(ctx context.Context, fullRescan bool) error {
ctx = context.WithoutCancel(ctx)
if !isScanning.TryLock() {
log.Debug("Scanner already running, ignoring request for rescan.")
return ErrAlreadyScanning
}
defer isScanning.Unlock()
var hasError bool
for folder := range s.folders {
err := s.rescan(ctx, folder, fullRescan)
hasError = hasError || err != nil
}
if hasError {
log.Error("Errors while scanning media. Please check the logs")
core.WriteAfterScanMetrics(ctx, s.ds, false)
return ErrScanError
}
core.WriteAfterScanMetrics(ctx, s.ds, true)
return nil
func contextWithoutCancel(ctx context.Context) context.Context {
return context.WithoutCancel(ctx)
}