Fixed a case where moving a file may be broken (when skipping duplicate MBID is active) + only check for duplicate track MBID (instead of recording MBID) as we have have several different releases sharing the same recording MBID)

This commit is contained in:
emeric
2023-02-22 13:58:18 +01:00
parent 12d967fe4f
commit 8a69d3e309
6 changed files with 29 additions and 10 deletions
@@ -283,16 +283,22 @@ namespace Scanner
Track::pointer track {Track::findByPath(dbSession, file) };
// Skip duplicate recording MBID
if (trackInfo->recordingMBID && _settings.skipDuplicateRecordingMBID)
// Skip duplicate track MBID
if (trackInfo->trackMBID && _settings.skipDuplicateMBID)
{
for (Track::pointer otherTrack : Track::findByRecordingMBID(dbSession, *trackInfo->recordingMBID))
for (Track::pointer otherTrack : Track::findByMBID(dbSession, *trackInfo->trackMBID))
{
// Skip ourselves
if (track && track->getId() == otherTrack->getId())
continue;
LMS_LOG(DBUPDATER, DEBUG) << "Skipped '" << file.string() << "' (similar recording MBID in '" << otherTrack->getPath().string() << "')";
// This recording MBID already exists, just remove what we just scanned
// Skip if the other track found does not exists, as it may have been moved to the current scanned file
std::error_code ec;
if (!std::filesystem::exists(otherTrack->getPath(), ec))
continue;
LMS_LOG(DBUPDATER, DEBUG) << "Skipped '" << file.string() << "' (similar MBID in '" << otherTrack->getPath().string() << "')";
// As this MBID already exists, just remove what we just scanned
if (track)
{
track.remove();
@@ -336,7 +336,7 @@ ScannerService::refreshScanSettings()
return;
LMS_LOG(DBUPDATER, DEBUG) << "Scanner settings updated";
LMS_LOG(DBUPDATER, DEBUG) << "skipDuplicateRecordingMBID = " << newSettings.skipDuplicateRecordingMBID;
LMS_LOG(DBUPDATER, DEBUG) << "skipDuplicateMBID = " << newSettings.skipDuplicateMBID;
LMS_LOG(DBUPDATER, DEBUG) << "Using scan settings version " << newSettings.scanVersion;
_settings = std::move(newSettings);
@@ -366,7 +366,7 @@ ScannerService::readSettings()
{
ScannerSettings newSettings;
newSettings.skipDuplicateRecordingMBID = Service<IConfig>::get()->getBool("scanner-skip-duplicate-recording-mbid", false);
newSettings.skipDuplicateMBID = Service<IConfig>::get()->getBool("scanner-skip-duplicate-mbid", false);
{
auto transaction {_dbSession.createSharedTransaction()};
@@ -36,7 +36,7 @@ namespace Scanner
std::vector<std::filesystem::path> supportedExtensions;
Database::ScanSettings::RecommendationEngineType recommendationServiceType;
std::filesystem::path mediaDirectory;
bool skipDuplicateRecordingMBID {};
bool skipDuplicateMBID {};
std::set<std::string> clusterTypeNames;
bool operator==(const ScannerSettings& rhs) const
@@ -47,7 +47,7 @@ namespace Scanner
&& supportedExtensions == rhs.supportedExtensions
&& recommendationServiceType == rhs.recommendationServiceType
&& mediaDirectory == rhs.mediaDirectory
&& skipDuplicateRecordingMBID == rhs.skipDuplicateRecordingMBID
&& skipDuplicateMBID == rhs.skipDuplicateMBID
&& clusterTypeNames == rhs.clusterTypeNames;
}
};