Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions db/migrations/20241026183640_support_new_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down