mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-13 10:47:19 +03:00
Better workaround for Go 1.20 missing context.WithoutCancel
This commit is contained in:
parent
d3f6b4692d
commit
0e3175ea17
@ -4,30 +4,8 @@ package scanner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"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 contextWithoutCancel(ctx context.Context) context.Context {
|
||||||
func (s *scanner) RescanAll(ctx context.Context, fullRescan bool) error {
|
return context.WithoutCancel(ctx)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -4,30 +4,9 @@ package scanner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/core"
|
|
||||||
"github.com/navidrome/navidrome/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO Remove this file when we drop support for go 1.20
|
// TODO Remove this file when we drop support for go 1.20
|
||||||
func (s *scanner) RescanAll(ctx context.Context, fullRescan bool) error {
|
func contextWithoutCancel(ctx context.Context) context.Context {
|
||||||
ctx = context.TODO()
|
return context.TODO()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,27 @@ func (s *scanner) setStatusEnd(folder string, lastUpdate time.Time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *scanner) RescanAll(ctx context.Context, fullRescan bool) error {
|
||||||
|
ctx = contextWithoutCancel(ctx)
|
||||||
|
if !isScanning.TryLock() {
|
||||||
|
log.Debug(ctx, "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(ctx, "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 (s *scanner) Status(mediaFolder string) (*StatusInfo, error) {
|
func (s *scanner) Status(mediaFolder string) (*StatusInfo, error) {
|
||||||
status, ok := s.getStatus(mediaFolder)
|
status, ok := s.getStatus(mediaFolder)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user