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:
Deluan Quintão 2025-03-11 10:09:09 -04:00 committed by GitHub
parent a28462a7ab
commit 2a15a217de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {