mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 03:30:39 +03:00
Fix fscache key mapping. Closes #1778
This commit is contained in:
parent
b7e50f7731
commit
321b3c5a64
12
utils/cache/spread_fs.go
vendored
12
utils/cache/spread_fs.go
vendored
@ -31,10 +31,10 @@ type spreadFS struct {
|
||||
//
|
||||
// dir is created with specified mode if it doesn't exist.
|
||||
func NewSpreadFS(dir string, mode os.FileMode) (*spreadFS, error) {
|
||||
fs := &spreadFS{root: dir, mode: mode, init: func() error {
|
||||
f := &spreadFS{root: dir, mode: mode, init: func() error {
|
||||
return os.MkdirAll(dir, mode)
|
||||
}}
|
||||
return fs, fs.init()
|
||||
return f, f.init()
|
||||
}
|
||||
|
||||
func (sfs *spreadFS) Reload(f func(key string, name string)) error {
|
||||
@ -50,7 +50,7 @@ func (sfs *spreadFS) Reload(f func(key string, name string)) error {
|
||||
|
||||
// Skip if name is not in the format XX/XX/XXXXXXXXXXXX
|
||||
parts := strings.Split(path, string(os.PathSeparator))
|
||||
if len(parts) != 3 || len(parts[0]) != 2 || len(parts[1]) != 2 {
|
||||
if len(parts) != 3 || len(parts[0]) != 2 || len(parts[1]) != 2 || len(parts[2]) != 40 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -97,6 +97,12 @@ func (sfs *spreadFS) RemoveAll() error {
|
||||
}
|
||||
|
||||
func (sfs *spreadFS) KeyMapper(key string) string {
|
||||
// When running the Haunter, fscache can call this KeyMapper with the cached filepath instead of the key.
|
||||
// That's because we don't inform the original cache keys when reloading in the Reload function above.
|
||||
// If that's the case, just return the file path, as it is the actual mapped key.
|
||||
if strings.HasPrefix(key, sfs.root) {
|
||||
return key
|
||||
}
|
||||
hash := fmt.Sprintf("%x", sha1.Sum([]byte(key)))
|
||||
return filepath.Join(sfs.root, hash[0:2], hash[2:4], hash)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user