diff --git a/src/lib/src/downloader/image-downloader.cpp b/src/lib/src/downloader/image-downloader.cpp index b05b9124c..bc7ee2046 100644 --- a/src/lib/src/downloader/image-downloader.cpp +++ b/src/lib/src/downloader/image-downloader.cpp @@ -78,8 +78,13 @@ void ImageDownloader::setBlacklist(Blacklist *blacklist) void ImageDownloader::save() { + // Try to build a path first if we don't need tags for the filename, to check for the "same dir" MD5 setting + const int filenameTagLevel = m_filename.needExactTags(m_image->parentSite(), m_profile->getSettings()); + const bool filenameNeedExactTags = filenameTagLevel == 2 || (filenameTagLevel == 1 && m_image->hasUnknownTag()); + const QString md5Path = !filenameNeedExactTags ? m_image->paths(m_filename, m_path, m_count).first() : QString(); + // We don't need to load the image details of files already in the MD5 list and that should be skipped - const QString md5action = m_profile->md5Action(m_image->md5(), {}).first; + const QString md5action = m_profile->md5Action(m_image->md5(), md5Path).first; if (md5action == "ignore" && !m_force) { loadedSave(Image::LoadTagsResult::Ok); return; diff --git a/src/lib/tests/src/downloader/image-downloader-test.cpp b/src/lib/tests/src/downloader/image-downloader-test.cpp index 7b6e416a5..1e795bc9e 100644 --- a/src/lib/tests/src/downloader/image-downloader-test.cpp +++ b/src/lib/tests/src/downloader/image-downloader-test.cpp @@ -304,14 +304,34 @@ TEST_CASE("ImageDownloader") SECTION("Skip details for existing images") { auto img = createImage(profile, site); - ImageDownloader downloader(profile, img, "%copyright%.%ext%", "tests/resources/tmp", 1, false, false, nullptr, true, false); + ImageDownloader downloader(profile, img, "something.%ext%", "tests/resources/tmp", 1, false, false, nullptr, true, false); QList expected; - expected.append({ QDir::toNativeSeparators("tests/resources/tmp/misc.jpg.tmp"), Image::Size::Full, Image::SaveResult::AlreadyExistsMd5 }); + expected.append({ QDir::toNativeSeparators("tests/resources/tmp/something.jpg.tmp"), Image::Size::Full, Image::SaveResult::AlreadyExistsMd5 }); profile->getSettings()->setValue("Save/md5Duplicates", "ignore"); + profile->getSettings()->setValue("Save/md5DuplicatesSameDir", "save"); + profile->getSettings()->setValue("Exec/SQL/image", "SELECT %copyright%"); + profile->addMd5(img->md5(), "tests/resources/image_1x1.png"); + + assertDownload(profile, img, &downloader, expected, false); + REQUIRE(img->token("copyright", QString()) == QString()); + } + + SECTION("Skip details for existing images (same dir)") + { + auto img = createImage(profile, site); + ImageDownloader downloader(profile, img, "something.%ext%", "tests/resources", 1, false, false, nullptr, true, false); + + QList expected; + expected.append({ QDir::toNativeSeparators("tests/resources/something.jpg.tmp"), Image::Size::Full, Image::SaveResult::AlreadyExistsMd5 }); + + profile->getSettings()->setValue("Save/md5Duplicates", "save"); + profile->getSettings()->setValue("Save/md5DuplicatesSameDir", "ignore"); + profile->getSettings()->setValue("Exec/SQL/image", "SELECT %copyright%"); profile->addMd5(img->md5(), "tests/resources/image_1x1.png"); assertDownload(profile, img, &downloader, expected, false); + REQUIRE(img->token("copyright", QString()) == QString()); } }