From c483c55d814ada7cee2551d37ee8cc4bc3affa10 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 08:29:07 +0100 Subject: [PATCH 1/2] Make thumbnails of files on other machines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A file on another machine (a Tailscale machine's, mounted by GVfs) got no thumbnail and no preview from thumbnailers given a URI: they ask GIO for the file, and GIO turns a path under the GVfs mounts back into its network address, sftp://…, which most can't open. Papers, which makes PDFs' thumbnails, said so ("not an absolute URI using the file scheme"), and every remote PDF showed the plain icon in its row and its details. Such a file now goes to the thumbnailer by a link in its scratch folder, named with the file's extension, which reads through the mount the same and which GIO leaves a file. A remote PDF's 128 and 1024 pixel thumbnails now take 150ms between them. Its failure was remembered, so it would never have been tried again. What failed is now remembered with the round it failed in, and one from before this is tried once more. Co-Authored-By: Claude Opus 5.5 --- src/thumbnails.cpp | 22 ++++++++++++++++++++-- tests/folio_tests.cpp | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/thumbnails.cpp b/src/thumbnails.cpp index fba5ff75..cc3e5c7f 100644 --- a/src/thumbnails.cpp +++ b/src/thumbnails.cpp @@ -1,4 +1,5 @@ #include "thumbnails.h" +#include "mounter.h" #include #include @@ -342,7 +343,18 @@ QImage Thumbnails::runThumbnailer(const QString &command, const QString &path, i if (!scratch.isValid()) return {}; const QString output = scratch.filePath("thumbnail.png"); - QStringList args = expandCommand(command, path, output, pixels); + // A thumbnailer given a URI asks GIO for the file, and GIO turns one on + // a GVfs mount (another machine's) back into its network address, + // sftp://…, which most can't open, Papers' among them. A link here reads + // through the mount the same, and GIO leaves it a file. + QString input = path; + if (path.startsWith(Mounter::root() + "/")) { + const QString suffix = QFileInfo(path).suffix(); + const QString link = scratch.filePath(suffix.isEmpty() ? "input" : "input." + suffix); + if (QFile::link(path, link)) + input = link; + } + QStringList args = expandCommand(command, input, output, pixels); if (args.isEmpty()) return {}; const QString program = args.takeFirst(); @@ -370,14 +382,20 @@ void Thumbnails::remember(QImage image, const QString &path, int size, const QDa save(std::move(image), cachePath(path, size), path, modified); } +// 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"); + void Thumbnails::rememberFailure(const QString &path, const QDateTime &modified) const { QImage marker(1, 1, QImage::Format_ARGB32); marker.fill(Qt::transparent); + marker.setText("X-Folio::Round", failedRound); save(std::move(marker), failPath(path), path, modified); } bool Thumbnails::failedBefore(const QString &path, const QDateTime &modified) const { - return madeFor(QImage(failPath(path)), modified); + const QImage marker(failPath(path)); + return madeFor(marker, modified) && marker.text("X-Folio::Round") == failedRound; } // Whether a cached thumbnail (or failure marker) was made from the file as it diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 3f606369..d021f87f 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -6231,6 +6231,23 @@ private slots: // the one it names. write(dir.filePath("photo.heic"), "not a real heic"); QCOMPARE(thumbnails.load(dir.filePath("photo.heic"), "image/*", 128).size(), QSize(64, 32)); + + // What failed is remembered with the round it failed in, and one + // remembered from before a fix (files on other machines) is tried + // again. + write(dir.filePath("broken.thumbnailer"), "[Thumbnailer Entry]\nExec=/bin/false %o\nMimeType=image/x-broken;\n"); + Thumbnails withBroken(dir.filePath("cache"), {dir.path()}); + 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. + 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())); + QVERIFY(old.save(dir.filePath("cache/fail/folio/" + Thumbnails::cacheKey(picture.filePath())))); + QVERIFY(!withBroken.load(picture.filePath(), "image/png", 128).isNull()); } void thumbnailsSetTextOnAPage() From ddec9543595421887a71bc769c8bc8b8bbdfaeab Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 08:35:29 +0100 Subject: [PATCH 2/2] Test that a file on another machine reaches its thumbnailer by a link Where GVfs mounts other machines is now given to Thumbnails (the real place unless a test gives its own), so a test can put a file there: its fake thumbnailer, given a URI, records it, and the test checks it's a file:// link with the file's extension, outside the mounts, while the thumbnail is kept under the file's own path, and that a file here goes as it is. Without the link the test fails. Co-Authored-By: Claude Opus 5.5 --- src/thumbnails.cpp | 8 +++++--- src/thumbnails.h | 6 +++++- tests/folio_tests.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/thumbnails.cpp b/src/thumbnails.cpp index cc3e5c7f..5a38991d 100644 --- a/src/thumbnails.cpp +++ b/src/thumbnails.cpp @@ -82,10 +82,12 @@ QStringList expandCommand(const QString &command, const QString &input, const QS } // namespace -Thumbnails::Thumbnails(const QString &cacheDirectory, const QStringList &thumbnailerDirectories) +Thumbnails::Thumbnails(const QString &cacheDirectory, const QStringList &thumbnailerDirectories, + const QString &remoteRoot) : m_cache(cacheDirectory.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/thumbnails" - : cacheDirectory) { + : cacheDirectory), + m_remoteRoot(remoteRoot.isEmpty() ? Mounter::root() : remoteRoot) { QStringList directories = thumbnailerDirectories; if (directories.isEmpty()) { // Later directories win, so the user's own thumbnailers override the @@ -348,7 +350,7 @@ QImage Thumbnails::runThumbnailer(const QString &command, const QString &path, i // sftp://…, which most can't open, Papers' among them. A link here reads // through the mount the same, and GIO leaves it a file. QString input = path; - if (path.startsWith(Mounter::root() + "/")) { + if (path.startsWith(m_remoteRoot + "/")) { const QString suffix = QFileInfo(path).suffix(); const QString link = scratch.filePath(suffix.isEmpty() ? "input" : "input." + suffix); if (QFile::link(path, link)) diff --git a/src/thumbnails.h b/src/thumbnails.h index b3ae4a80..531e9c8d 100644 --- a/src/thumbnails.h +++ b/src/thumbnails.h @@ -17,7 +17,10 @@ // tile asks for it: there is no background crawl. class Thumbnails { public: - explicit Thumbnails(const QString &cacheDirectory = {}, const QStringList &thumbnailerDirectories = {}); + // `remoteRoot` is where GVfs mounts other machines (Mounter::root()); + // tests give their own. + explicit Thumbnails(const QString &cacheDirectory = {}, const QStringList &thumbnailerDirectories = {}, + const QString &remoteRoot = {}); // Returns a thumbnail no larger than `size` on its longest side, from the // cache when it is fresh, or a null image when none can be made. @@ -56,6 +59,7 @@ class Thumbnails { static bool madeFor(const QImage &image, const QDateTime &modified); QString m_cache; + QString m_remoteRoot; QHash m_thumbnailers; }; diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index d021f87f..b2683846 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -6250,6 +6250,45 @@ private slots: QVERIFY(!withBroken.load(picture.filePath(), "image/png", 128).isNull()); } + // A file on another machine goes to a thumbnailer given a URI by a link + // to it, a file:// one with its extension: GIO would turn the mount's + // own path back into sftp://, which most thumbnailers can't open. The + // thumbnail is still kept under the file's own path. + void thumbnailsReachOtherMachinesByALink() + { + QTemporaryDir dir; + QImage frame(64, 32, QImage::Format_RGB32); + frame.fill(Qt::green); + QVERIFY(frame.save(dir.filePath("frame.png"))); + // Says what it was given, and makes the frame its thumbnail. + write(dir.filePath("record"), "#!/bin/sh\necho \"$1\" > \"" + dir.filePath("given").toUtf8() + + "\"\ncp \"" + dir.filePath("frame.png").toUtf8() + "\" \"$2\"\n"); + QVERIFY(QFile::setPermissions(dir.filePath("record"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)); + write(dir.filePath("record.thumbnailer"), + "[Thumbnailer Entry]\nExec=" + dir.filePath("record").toUtf8() + " %u %o\nMimeType=application/pdf;\n"); + QDir(dir.path()).mkpath("gvfs/sftp:host=far/home"); + const QString remote = dir.filePath("gvfs/sftp:host=far/home/Order 42.pdf"); + write(remote, "%PDF"); + Thumbnails thumbnails(dir.filePath("cache"), {dir.path()}, dir.filePath("gvfs")); + + QVERIFY(!thumbnails.load(remote, "application/pdf", 128).isNull()); + QFile given(dir.filePath("given")); + QVERIFY(given.open(QIODevice::ReadOnly)); + const QUrl url(QString::fromUtf8(given.readAll()).trimmed()); + QCOMPARE(url.scheme(), QString("file")); + QVERIFY2(!url.toLocalFile().startsWith(dir.filePath("gvfs")), qPrintable(url.toString())); + QCOMPARE(QFileInfo(url.toLocalFile()).fileName(), QString("input.pdf")); + QVERIFY(QFile::exists(dir.filePath("cache/normal/" + Thumbnails::cacheKey(remote)))); + + // A file here goes as it is. + const QString local = dir.filePath("Order 43.pdf"); + write(local, "%PDF"); + QVERIFY(!thumbnails.load(local, "application/pdf", 128).isNull()); + given.close(); + QVERIFY(given.open(QIODevice::ReadOnly)); + QCOMPARE(QUrl(QString::fromUtf8(given.readAll()).trimmed()).toLocalFile(), local); + } + void thumbnailsSetTextOnAPage() { QTemporaryDir dir;