Skip to content

Commit

Permalink
fix: handle MD5 "same dir" for early download exit (fix #3140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed May 5, 2024
1 parent 7038185 commit 70073d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/lib/src/downloader/image-downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions src/lib/tests/src/downloader/image-downloader-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageSaveResult> 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<ImageSaveResult> 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());
}
}

0 comments on commit 70073d6

Please sign in to comment.