From 015e3e6aea6eed57bf93f183b96b95088c819c8e Mon Sep 17 00:00:00 2001 From: GM Date: Wed, 11 Nov 2026 09:47:40 -0400 Subject: [PATCH 1/2] Hand a thumbnailer a name that holds a code as it is A thumbnailer's command was filled in one code after another, so a file called 50%off.mp4 had the %o in its own name replaced by the output path. The thumbnailer was sent a file that is not there, and the failure was remembered. Each code is now read once. Co-Authored-By: Claude Opus 5.5 --- src/thumbnails.cpp | 25 ++++++++++++++++++++++--- tests/folio_tests.cpp | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/thumbnails.cpp b/src/thumbnails.cpp index d191a272..cdce1eef 100644 --- a/src/thumbnails.cpp +++ b/src/thumbnails.cpp @@ -70,12 +70,31 @@ QByteArray withPlainText(const QByteArray &png) { return out; } -// The spec's Exec field: %i input path, %u input URI, %o output, %s size. +// The spec's Exec field, such as "ffmpegthumbnailer -i %i -o %o -s %s -f": %i input path, %u input URI, %o output, %s size, %% a percent sign. +// Each code is read once, so a name that holds one arrives as it is. QStringList expandCommand(const QString &command, const QString &input, const QString &output, int size) { QStringList args = QProcess::splitCommand(command); for (QString &arg : args) { - arg.replace("%i", input).replace("%u", fileUri(input)).replace("%o", output) - .replace("%s", QString::number(size)).replace("%%", "%"); + QString expanded; + for (qsizetype at = 0; at < arg.size(); ++at) { + const QChar code = arg.at(at) == '%' && at + 1 < arg.size() ? arg.at(at + 1) : QChar(); + if (code == 'i') + expanded += input; + else if (code == 'u') + expanded += fileUri(input); + else if (code == 'o') + expanded += output; + else if (code == 's') + expanded += QString::number(size); + else if (code == '%') + expanded += '%'; + else { + expanded += arg.at(at); + continue; + } + ++at; + } + arg = expanded; } return args; } diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index d4cfcbe5..d5a32dba 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -6402,6 +6402,26 @@ private slots: QVERIFY(QFile::exists(dir.filePath("cache/fail/folio/" + Thumbnails::cacheKey(dir.filePath("clip.mp4"))))); } + void thumbnailsHandAThumbnailerANameThatHoldsACode() + { + QTemporaryDir dir; + // The thumbnailer copies its input out and notes the third argument it was given beside itself. + const QString script = dir.filePath("copy.sh"); + write(script, "cp \"$1\" \"$2\" && printf %s \"$3\" > \"$0.said\"\n"); + write(dir.filePath("demo.thumbnailer"), "[Thumbnailer Entry]\nExec=/bin/sh \"" + script.toUtf8() + + "\" %i %o \"--size=%s,%s 100%% %u\"\nMimeType=video/mp4;\n"); + Thumbnails thumbnails(dir.filePath("cache"), {dir.path()}); + + // A name with every code in it is still one file to the thumbnailer, by path and by URI. + const QString clip = dir.filePath("50%off %sale %up %in 100%%.mp4"); + QVERIFY(QImage(10, 20, QImage::Format_RGB32).save(clip, "PNG")); + QCOMPARE(thumbnails.load(clip, "video/mp4", 128).size(), QSize(10, 20)); + QFile said(script + ".said"); + QVERIFY(said.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromUtf8(said.readAll()), + "--size=128,128 100% " + QUrl::fromLocalFile(clip).toString(QUrl::FullyEncoded)); + } + void thumbnailsRememberOnlyWhatFailed() { QTemporaryDir dir; From 25e034e5d506fd4cdb2a2ba856c683b1f912b962 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 16:00:52 +0100 Subject: [PATCH 2/2] Try again what failed before these thumbnail fixes Files that failed only because of what's fixed here (a name holding a %, a helper that never started, a camera RAW Folio couldn't read) kept their failure markers, and those hold a file back before any of the fixes are reached, so they stayed blank until the file changed. The markers' round goes to 3, so each is tried once more. The same change is in each of the thumbnail fixes, so they merge in any order. Co-Authored-By: Claude Opus 5.5 --- src/thumbnails.cpp | 5 +++-- tests/folio_tests.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/thumbnails.cpp b/src/thumbnails.cpp index cdce1eef..79e0c408 100644 --- a/src/thumbnails.cpp +++ b/src/thumbnails.cpp @@ -404,8 +404,9 @@ void Thumbnails::remember(QImage image, const QString &path, int size, const QDa } // Markers say which round of thumbnailing failed: ones from before a fix -// (round 2: files on other machines) are tried again once. -static const QString failedRound = QStringLiteral("2"); +// (round 2: files on other machines; round 3: names holding a %, helpers +// that never started, camera RAW) are tried again once. +static const QString failedRound = QStringLiteral("3"); void Thumbnails::rememberFailure(const QString &path, const QDateTime &modified) const { QImage marker(1, 1, QImage::Format_ARGB32); diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index d5a32dba..28ce8bed 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -6451,12 +6451,13 @@ private slots: write(dir.filePath("never.broken"), "x"); QVERIFY(withBroken.load(dir.filePath("never.broken"), "image/x-broken", 128).isNull()); const QImage marker(dir.filePath("cache/fail/folio/" + Thumbnails::cacheKey(dir.filePath("never.broken")))); - QCOMPARE(marker.text("X-Folio::Round"), QString("2")); - // An old marker, without its round, for a picture that can be made. + QCOMPARE(marker.text("X-Folio::Round"), QString("3")); + // A marker from round 2, for a picture that can be made. const QFileInfo picture(dir.filePath("frame.png")); QImage old(1, 1, QImage::Format_ARGB32); old.setText("Thumb::MTime", QString::number(picture.lastModified().toSecsSinceEpoch())); old.setText("X-Folio::MTime", QString::number(picture.lastModified().toMSecsSinceEpoch())); + old.setText("X-Folio::Round", "2"); QVERIFY(old.save(dir.filePath("cache/fail/folio/" + Thumbnails::cacheKey(picture.filePath())))); QVERIFY(!withBroken.load(picture.filePath(), "image/png", 128).isNull()); }