mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-01 19:47:37 +03:00
fix(server): db migration does not work for MusicFolders ending with a trailing slash. (#3797)
* fix(server): db migration was not working for MusicFolders ending with a trailing slash. Signed-off-by: Deluan <deluan@navidrome.org> * fix(server): db migration for relative paths Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
a28462a7ab
commit
2a15a217de
1 changed files with 7 additions and 2 deletions
|
@ -178,7 +178,7 @@ join library on media_file.library_id = library.id`, string(os.PathSeparator)))
|
|||
f := model.NewFolder(lib, path)
|
||||
_, err = stmt.ExecContext(ctx, f.ID, lib.ID, f.Path, f.Name, f.ParentID)
|
||||
if err != nil {
|
||||
log.Error("Error writing folder to DB", "path", path, err)
|
||||
log.Error("error writing folder to DB", "path", path, err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
@ -187,7 +187,12 @@ join library on media_file.library_id = library.id`, string(os.PathSeparator)))
|
|||
return fmt.Errorf("error populating folder table: %w", err)
|
||||
}
|
||||
|
||||
libPathLen := utf8.RuneCountInString(lib.Path)
|
||||
// Count the number of characters in the library path
|
||||
libPath := filepath.Clean(lib.Path)
|
||||
libPathLen := utf8.RuneCountInString(libPath)
|
||||
|
||||
// In one go, update all paths in the media_file table, removing the library path prefix
|
||||
// and replacing any backslashes with slashes (the path separator used by the io/fs package)
|
||||
_, err = tx.ExecContext(ctx, fmt.Sprintf(`
|
||||
update media_file set path = replace(substr(path, %d), '\', '/');`, libPathLen+2))
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue