Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporary fix for scan context cancellation for Go 1.20
- Loading branch information
Showing
3 changed files
with
66 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build go1.21 | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build !go1.21 | ||
|
||
package scanner | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/navidrome/navidrome/core" | ||
"github.com/navidrome/navidrome/log" | ||
) | ||
|
||
// TODO Remove this file when we drop support for go 1.20 | ||
func (s *scanner) RescanAll(ctx context.Context, fullRescan bool) error { | ||
ctx = 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters