SongLoader: Try resolve symbolic links to match collection directory

This commit is contained in:
Jonas Kvinge 2024-10-06 15:42:03 +02:00
parent 1d9b8f464a
commit 256cc7d15c
1 changed files with 14 additions and 19 deletions

View File

@ -225,29 +225,24 @@ SongLoader::Result SongLoader::LoadLocal(const QString &filename) {
qLog(Debug) << "Loading local file" << filename;
// Search in the database.
QUrl url = QUrl::fromLocalFile(filename);
QMutexLocker l(collection_backend_->db()->Mutex());
QSqlDatabase db(collection_backend_->db()->Connect());
CollectionQuery query(db, collection_backend_->songs_table());
query.SetColumnSpec(QStringLiteral("%songs_table.ROWID, ") + Song::kColumnSpec);
query.AddWhere(QStringLiteral("url"), url.toEncoded());
if (query.Exec() && query.Next()) {
// We may have many results when the file has many sections
do {
Song song(Song::Source::Collection);
song.InitFromQuery(query, true);
if (song.is_valid()) {
songs_ << song;
}
} while (query.Next());
const QUrl url = QUrl::fromLocalFile(filename);
SongList songs = collection_backend_->GetSongsByUrl(url);
if (!songs.isEmpty()) {
songs_ = songs;
return Result::Success;
}
const QString canonical_filepath = QFileInfo(filename).canonicalFilePath();
if (!canonical_filepath.isEmpty() && canonical_filepath != filename) {
const QUrl canonical_filepath_url = QUrl::fromLocalFile(canonical_filepath);
songs = collection_backend_->GetSongsByUrl(canonical_filepath_url);
if (!songs.isEmpty()) {
songs_ = songs;
return Result::Success;
}
}
// It's not in the database, load it asynchronously.
preload_func_ = std::bind(&SongLoader::LoadLocalAsync, this, filename);
return Result::BlockingLoadRequired;