From 96fab5d57eaf66379a4d7334ed210aee44259bda Mon Sep 17 00:00:00 2001 From: emeric Date: Wed, 22 Feb 2023 22:18:24 +0100 Subject: [PATCH] Fixed codeQL issue + fixed bad db migration. fixes #308 --- .../include/services/database/Track.hpp | 1 + .../scanner/impl/ScanStepScanFiles.cpp | 19 ++++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/libs/services/database/include/services/database/Track.hpp b/src/libs/services/database/include/services/database/Track.hpp index 1bf894ab..dd9b3428 100644 --- a/src/libs/services/database/include/services/database/Track.hpp +++ b/src/libs/services/database/include/services/database/Track.hpp @@ -126,6 +126,7 @@ class Track : public Object void setTotalDisc(std::optional totalDisc) { _totalDisc = totalDisc ? *totalDisc : 0; } void setDiscSubtitle(const std::string& name) { _discSubtitle = name; } void setName(const std::string& name) { _name = std::string(name, 0, _maxNameLength); } + void setPath(const std::filesystem::path& filePath) { _filePath = filePath; } void setDuration(std::chrono::milliseconds duration) { _duration = duration; } void setLastWriteTime(Wt::WDateTime time) { _fileLastWrite = time; } void setAddedTime(Wt::WDateTime time) { _fileAdded = time; } diff --git a/src/libs/services/scanner/impl/ScanStepScanFiles.cpp b/src/libs/services/scanner/impl/ScanStepScanFiles.cpp index 6eca608a..4df5dd71 100644 --- a/src/libs/services/scanner/impl/ScanStepScanFiles.cpp +++ b/src/libs/services/scanner/impl/ScanStepScanFiles.cpp @@ -287,19 +287,16 @@ namespace Scanner { std::vector duplicateTracks {Track::findByMBID(dbSession, *trackInfo->trackMBID)}; - if (!track) + // find for existing MBIDs as the file may have just been moved + if (!track && duplicateTracks.size() == 1) { - // find for existing MBIDs as the file may have just been moved - const auto duplicateTracks {Track::findByMBID(dbSession, *trackInfo->trackMBID)}; - if (duplicateTracks.size() == 1) + Track::pointer otherTrack {duplicateTracks.front()}; + std::error_code ec; + if (!std::filesystem::exists(otherTrack->getPath(), ec)) { - Track::pointer otherTrack {duplicateTracks.front()}; - std::error_code ec; - if (!std::filesystem::exists(otherTrack->getPath(), ec)) - { - LMS_LOG(DBUPDATER, DEBUG) << "Considering track '" << file.string() << "' moved from '" << otherTrack->getPath() << "'"; - track = otherTrack; - } + LMS_LOG(DBUPDATER, DEBUG) << "Considering track '" << file.string() << "' moved from '" << otherTrack->getPath() << "'"; + track = otherTrack; + track.modify()->setPath(file); } }