Fixed codeQL issue + fixed bad db migration. fixes #308

This commit is contained in:
emeric
2023-02-22 22:18:24 +01:00
parent 492e2d4fc6
commit 96fab5d57e
2 changed files with 9 additions and 11 deletions
@@ -126,6 +126,7 @@ class Track : public Object<Track, TrackId>
void setTotalDisc(std::optional<int> totalDisc) { _totalDisc = totalDisc ? *totalDisc : 0; } void setTotalDisc(std::optional<int> totalDisc) { _totalDisc = totalDisc ? *totalDisc : 0; }
void setDiscSubtitle(const std::string& name) { _discSubtitle = name; } void setDiscSubtitle(const std::string& name) { _discSubtitle = name; }
void setName(const std::string& name) { _name = std::string(name, 0, _maxNameLength); } 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 setDuration(std::chrono::milliseconds duration) { _duration = duration; }
void setLastWriteTime(Wt::WDateTime time) { _fileLastWrite = time; } void setLastWriteTime(Wt::WDateTime time) { _fileLastWrite = time; }
void setAddedTime(Wt::WDateTime time) { _fileAdded = time; } void setAddedTime(Wt::WDateTime time) { _fileAdded = time; }
@@ -287,11 +287,8 @@ namespace Scanner
{ {
std::vector<Track::pointer> duplicateTracks {Track::findByMBID(dbSession, *trackInfo->trackMBID)}; std::vector<Track::pointer> duplicateTracks {Track::findByMBID(dbSession, *trackInfo->trackMBID)};
if (!track)
{
// find for existing MBIDs as the file may have just been moved // find for existing MBIDs as the file may have just been moved
const auto duplicateTracks {Track::findByMBID(dbSession, *trackInfo->trackMBID)}; if (!track && duplicateTracks.size() == 1)
if (duplicateTracks.size() == 1)
{ {
Track::pointer otherTrack {duplicateTracks.front()}; Track::pointer otherTrack {duplicateTracks.front()};
std::error_code ec; std::error_code ec;
@@ -299,7 +296,7 @@ namespace Scanner
{ {
LMS_LOG(DBUPDATER, DEBUG) << "Considering track '" << file.string() << "' moved from '" << otherTrack->getPath() << "'"; LMS_LOG(DBUPDATER, DEBUG) << "Considering track '" << file.string() << "' moved from '" << otherTrack->getPath() << "'";
track = otherTrack; track = otherTrack;
} track.modify()->setPath(file);
} }
} }