From 302707a2726e112a86aace3a5f7b181fa9bab441 Mon Sep 17 00:00:00 2001 From: Jaxon Wright Date: Thu, 12 Nov 2026 09:36:41 -0500 Subject: [PATCH 1/4] Show a file's permissions, and make one's own files executable or not The details pane gains a Permissions row, as ls writes them, read with the rest of the details off the UI thread; it keeps its place while they're read, and isn't shown in the trash. The menu on one's own files gains Make Executable, or Make Not Executable when they all run already: it lets whoever may read a file run it, so a private file stays private, and takes running away from everyone. Folders, whose x means something else, links, and other people's files don't get it. The pane reads the item again when its permissions change, since the folder looks the same. Co-Authored-By: Claude Opus 5.5 --- src/FileMenu.qml | 26 ++++++++++++++----- src/PreviewPane.qml | 21 +++++++++++++++ src/backend.cpp | 15 +++++++++++ src/fileops.cpp | 40 +++++++++++++++++++++++++++++ src/fileops.h | 8 ++++++ src/i18n/en.json | 5 ++++ tests/folio_tests.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 168 insertions(+), 7 deletions(-) diff --git a/src/FileMenu.qml b/src/FileMenu.qml index 5e1ecb7c..a0c315a0 100644 --- a/src/FileMenu.qml +++ b/src/FileMenu.qml @@ -1,13 +1,14 @@ import QtQuick // The right-click menu. On an item: Open, Open With (each app that can), -// Preview, Rename, Duplicate, Copy, Cut, Paste Into, Copy Path, Compress, -// Extract (for archives), Burn (for disk images), plugins' own actions for -// it, Share (whatever plugins offer for it), Pin, Terminal, Trash. On empty -// space: Undo, Paste, New Folder, Copy Path, Terminal, hidden files. In the -// trash: Restore, Empty Trash and Delete…, without the entries that change -// files or plugins' actions. On a plugin's item: Open, and nothing for files. Entries show their -// keys, so the menu also teaches the shortcuts. +// Preview, Rename, Duplicate, Make Executable (for one's own files), Copy, +// Cut, Paste Into, Copy Path, Compress, Extract (for archives), Burn (for +// disk images), plugins' own actions for it, Share (whatever plugins offer +// for it), Pin, Terminal, Trash. On empty space: Undo, Paste, New Folder, +// Copy Path, Terminal, hidden files. In the trash: Restore, Empty Trash and +// Delete…, without the entries that change files or plugins' actions. On a +// plugin's item: Open, and nothing for files. Entries show their keys, so +// the menu also teaches the shortcuts. FolioMenu { id: fileMenu @@ -45,6 +46,10 @@ FolioMenu { // as the menu opens rather than on every binding. property bool canBurn: false property var burnTargets: [] + // Whether these are one's own files that can be made to run or not, and + // whether they all run now, asked as the menu opens. + property bool canRun: false + property bool runs: false // Opens at the pointer (`at`, in the window), or (from the keyboard, // Alt+Return) beside the item it's about. Mirrored, it opens leftward, @@ -61,6 +66,8 @@ FolioMenu { return canBurn = forItem && forFiles && !trashView && !forSelection && fileOps.canBurn(target.path) burnTargets = canBurn ? fileOps.burnTargets(target.path) : [] + canRun = forItem && forFiles && !trashView && fileOps.canSetExecutable(paths) + runs = canRun && fileOps.executable(paths) // Submenus (Open With, Share, Burn) show only when they apply. // Menu makes their entries itself, so they're set here rather than // bound where they're declared. A plugin's own submenus are made @@ -158,6 +165,11 @@ FolioMenu { keys: "Ctrl+Shift+D" onTriggered: fileOps.duplicate(fileMenu.target.path) } + FolioMenuItem { + shown: fileMenu.canRun + text: fileMenu.runs ? qsTr("Make Not Executable") : qsTr("Make Executable") + onTriggered: fileOps.setExecutable(fileMenu.paths, !fileMenu.runs) + } FolioMenuItem { shown: fileMenu.forItem && fileMenu.forFiles text: qsTr("Copy") diff --git a/src/PreviewPane.qml b/src/PreviewPane.qml index 5cc8a970..527f3b98 100644 --- a/src/PreviewPane.qml +++ b/src/PreviewPane.qml @@ -54,6 +54,12 @@ Rectangle { // Gone (a folder selected, or another view), it describes nothing, so // plugins stop being asked about the file it showed last. Component.onDestruction: backend.describe({}, false) + // Made executable or not from the menu: the item looks the same in the + // folder, so its permissions are read again here. + Connections { + target: pane.folderPane ? pane.folderPane.paneFileOps : null + function onModesChanged(paths) { if (pane.hasItem && paths.includes(pane.item.path)) pane.describe() } + } // It sits on the columns' background, and their separator marks its // edge. @@ -259,6 +265,21 @@ Rectangle { color: theme.foreground size: 12 } + // As ls writes them; Make Executable in the menu changes them. The + // row keeps its place while they're read, so moving through files + // doesn't shift the rows below it. Not in the trash, where nothing + // changes them. + readonly property bool permissionsShown: pane.hasItem && !pane.trashed && !pane.pluginItem + && pane.item.path.startsWith("/") + FolioText { visible: parent.permissionsShown; text: qsTr("Permissions"); color: theme.secondaryForeground; size: 12 } + FolioText { + visible: parent.permissionsShown + Layout.fillWidth: true + horizontalAlignment: Text.AlignRight + text: pane.info.permissions || "" + color: theme.foreground + size: 12 + } FolioText { visible: !!pane.drive; text: qsTr("Free space"); color: theme.secondaryForeground; size: 12} FolioText { visible: !!pane.drive diff --git a/src/backend.cpp b/src/backend.cpp index 878f98ba..5c8c6186 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include Backend::Backend(const QString &home, QObject *parent) @@ -446,6 +447,18 @@ QString Backend::takeSelection() { return name; } +// As ls writes them: read, write and run for the owner, the group and +// everyone, with the setuid, setgid and sticky bits in the run places. +static QString permissionsText(mode_t mode) { + const auto run = [mode](mode_t x, mode_t special, char set, char setOnly) { + return mode & special ? (mode & x ? set : setOnly) : (mode & x ? 'x' : '-'); + }; + const char text[] = {mode & S_IRUSR ? 'r' : '-', mode & S_IWUSR ? 'w' : '-', run(S_IXUSR, S_ISUID, 's', 'S'), + mode & S_IRGRP ? 'r' : '-', mode & S_IWGRP ? 'w' : '-', run(S_IXGRP, S_ISGID, 's', 'S'), + mode & S_IROTH ? 'r' : '-', mode & S_IWOTH ? 'w' : '-', run(S_IXOTH, S_ISVTX, 't', 'T'), 0}; + return QString::fromLatin1(text); +} + void Backend::describe(const QVariantMap &item, bool inTrash) { const QString path = item.value("path").toString(); const QString kind = item.value("kind").toString(); @@ -489,6 +502,8 @@ void Backend::describe(const QVariantMap &item, bool inTrash) { QVariantMap read; if (*latest != generation) return read; + if (struct stat st; ::stat(QFile::encodeName(path).constData(), &st) == 0) + read.insert("permissions", permissionsText(st.st_mode)); if (inTrash) { read.insert("origin", FileOps::originalPath(path)); read.insert("deleted", FileOps::deletedAt(path)); diff --git a/src/fileops.cpp b/src/fileops.cpp index ca1b5f80..df2db47e 100644 --- a/src/fileops.cpp +++ b/src/fileops.cpp @@ -1043,6 +1043,46 @@ void FileOps::compress(const QStringList &selected) { connect(process, &QProcess::readyReadStandardError, this, [process, read] { read(process); }); } +// Only the owner may change a file's mode, so it's offered for one's own. +static bool ownFile(const QString &path, struct stat *st) { + return ::lstat(QFile::encodeName(path).constData(), st) == 0 && S_ISREG(st->st_mode) && st->st_uid == ::geteuid(); +} + +bool FileOps::canSetExecutable(const QStringList &paths) const { + struct stat st; + return !paths.isEmpty() && std::all_of(paths.begin(), paths.end(), [&st](const QString &path) { return ownFile(path, &st); }); +} + +bool FileOps::executable(const QStringList &paths) const { + struct stat st; + return !paths.isEmpty() && std::all_of(paths.begin(), paths.end(), [&st](const QString &path) { + return ownFile(path, &st) && (st.st_mode & S_IXUSR); + }); +} + +void FileOps::setExecutable(const QStringList &paths, bool on) { + QStringList changed, failures; + for (const QString &path : paths) { + struct stat st; + if (!ownFile(path, &st)) + continue; + // Whoever may read it may run it, so a file kept private stays so; + // off, no one may. + const mode_t read = st.st_mode & (S_IRUSR | S_IRGRP | S_IROTH); + const mode_t mode = on ? (st.st_mode | read >> 2) : (st.st_mode & ~(S_IXUSR | S_IXGRP | S_IXOTH)); + // Never through a link put there since it was looked at. + if (::fchmodat(AT_FDCWD, QFile::encodeName(path).constData(), mode & 07777, AT_SYMLINK_NOFOLLOW) == 0) + changed << path; + else + failures << tr("%1 (%2)").arg(QFileInfo(path).fileName(), QString::fromLocal8Bit(strerror(errno))); + } + if (!changed.isEmpty()) + emit modesChanged(changed); + if (!failures.isEmpty()) + emit failed((on ? tr("Couldn't make %1 executable.") : tr("Couldn't make %1 not executable.")) + .arg(QLocale().createSeparatedList(failures))); +} + bool FileOps::canExtract(const QStringList &paths) const { // A lone compressed file (notes.txt.gz) is no archive to bsdtar, and a // disk image is for burning, not unpacking. diff --git a/src/fileops.h b/src/fileops.h index cea4af16..f8626a7c 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -117,6 +117,12 @@ class FileOps : public QObject { // Unpacks each archive beside itself: an archive of one item gives // that item, one of several a folder named after the archive. Q_INVOKABLE void extract(const QStringList &paths); + // Whether these are all files of one's own that can be made to run or + // not: never a folder, whose x means something else, nor a link. + Q_INVOKABLE bool canSetExecutable(const QStringList &paths) const; + // Whether each of them runs as a program already. + Q_INVOKABLE bool executable(const QStringList &paths) const; + Q_INVOKABLE void setExecutable(const QStringList &paths, bool on); Q_INVOKABLE void trash(const QStringList &paths); @@ -277,6 +283,8 @@ class FileOps : public QObject { void busyChanged(); void clipboardChanged(); void failed(const QString &message); + // Files whose permissions setExecutable changed. + void modesChanged(const QStringList &paths); void notice(const QString ¬ice); void clashChanged(); void historyChanged(); diff --git a/src/i18n/en.json b/src/i18n/en.json index c2bd349a..4da6fe88 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -113,6 +113,8 @@ "Couldn't extract %1: it's damaged, or isn't an archive Folio can read.": "Couldn't extract %1: it's damaged, or isn't an archive Folio can read.", "Couldn't extract %1: it's protected by a password.": "Couldn't extract %1: it's protected by a password.", "Couldn't format %1. %2": "Couldn't format %1. %2", + "Couldn't make %1 executable.": "Couldn't make %1 executable.", + "Couldn't make %1 not executable.": "Couldn't make %1 not executable.", "Couldn't make %1 the default app for %2: %3": "Couldn't make %1 the default app for %2: %3", "Couldn't move %1 to the trash to replace it: %2": "Couldn't move %1 to the trash to replace it: %2", "Couldn't move %1 to the trash: %2": "Couldn't move %1 to the trash: %2", @@ -217,6 +219,8 @@ "Keep Both": "Keep Both", "Keyboard shortcuts": "Keyboard shortcuts", "Kind": "Kind", + "Make Executable": "Make Executable", + "Make Not Executable": "Make Not Executable", "Making a preview…": "Making a preview…", "Merge": "Merge", "Merging adds what's in this folder to the one there. What has the same name inside is replaced, and the replaced items go to the trash.": "Merging adds what's in this folder to the one there. What has the same name inside is replaced, and the replaced items go to the trash.", @@ -278,6 +282,7 @@ "Paste Into Folder": "Paste Into Folder", "Pause (K)": "Pause (K)", "Permission was refused.": "Permission was refused.", + "Permissions": "Permissions", "Pin": "Pin", "Pin or unpin the folder": "Pin or unpin the folder", "Pinned": "Pinned", diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 6a0aeeb4..f3372d90 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -1415,6 +1415,49 @@ private slots: QCOMPARE(FileOps::foldHandlerRepeats({other, writer, twin}), QVariantList({other, writer, twin})); } + void fileOpsMakesFilesExecutable() + { + // Run is allowed for whoever may read, and taken away from + // everyone. Only for one's own files: not folders, whose x means + // something else, nor links. + QTemporaryDir dir; + const QString script = dir.filePath("run.sh"), secret = dir.filePath("secret.sh"), + link = dir.filePath("link"), folder = dir.filePath("folder"); + write(script, "#!/bin/sh\n"); + write(secret, "#!/bin/sh\n"); + QCOMPARE(::chmod(QFile::encodeName(script).constData(), 0644), 0); + QCOMPARE(::chmod(QFile::encodeName(secret).constData(), 0600), 0); + QVERIFY(QFile::link(script, link)); + QVERIFY(QDir().mkdir(folder)); + const auto mode = [](const QString &path) { + struct stat st; + return ::stat(QFile::encodeName(path).constData(), &st) == 0 ? st.st_mode & 07777 : 0u; + }; + FileOps ops; + QVERIFY(ops.canSetExecutable({script, secret})); + QVERIFY(!ops.canSetExecutable({script, folder})); + QVERIFY(!ops.canSetExecutable({link})); + QVERIFY(!ops.canSetExecutable({})); + if (::geteuid() != 0) + QVERIFY(!ops.canSetExecutable({"/etc/hostname"})); + QVERIFY(!ops.executable({script, secret})); + + // The details pane reads the item again on hearing which changed. + QSignalSpy changed(&ops, &FileOps::modesChanged); + ops.setExecutable({script, secret, folder}, true); + QCOMPARE(changed.count(), 1); + QCOMPARE(changed.at(0).at(0).toStringList(), QStringList({script, secret})); + QCOMPARE(mode(script), 0755u); + QCOMPARE(mode(secret), 0700u); + QVERIFY(ops.executable({script, secret})); + QCOMPARE(::chmod(QFile::encodeName(secret).constData(), 0600), 0); + QVERIFY(!ops.executable({script, secret})); + + ops.setExecutable({script, secret}, false); + QCOMPARE(mode(script), 0644u); + QCOMPARE(mode(secret), 0600u); + } + void fileOpsDeleteForeverOutsideTheTrash() { // Shift+Delete deletes for good anywhere: the folder and what's in @@ -4279,6 +4322,23 @@ private slots: QVERIFY2(!said().contains(pdfName) && !said().contains("Reader"), qPrintable(said())); } + void backendShowsWhoMayReadWriteAndRun() + { + // Any file or folder's permissions, as ls writes them, read with + // the rest of the details. + QTemporaryDir dir; + const QString report = dir.filePath("report.pdf"), tools = dir.filePath("tools"); + write(report, "x"); + QVERIFY(QDir().mkdir(tools)); + QCOMPARE(::chmod(QFile::encodeName(report).constData(), 0640), 0); + QCOMPARE(::chmod(QFile::encodeName(tools).constData(), 01755), 0); + Backend backend(dir.path()); + backend.describe({{"path", report}, {"kind", "pdf"}, {"mime", "application/pdf"}}); + QTRY_COMPARE(backend.details().value("permissions").toString(), QString("rw-r-----")); + backend.describe({{"path", tools}, {"kind", "folder"}, {"mime", "inode/directory"}}); + QTRY_COMPARE(backend.details().value("permissions").toString(), QString("rwxr-xr-t")); + } + void backendReadsTrashNotesOffTheUiThread() { // Finding a trashed item's note looks over every mounted drive, so From 85eb2cf59ea20d3d38d565190377e491d046f0ae Mon Sep 17 00:00:00 2001 From: Jaxon Wright Date: Wed, 18 Nov 2026 15:57:15 +0100 Subject: [PATCH 2/4] Keep the details' reads off the listing threads, and change the file looked at Moving across folders on a mount that stopped answering left a stuck stat per folder in the shared pool, and once those filled it no folder could be listed: the readings now have four threads of their own. The permissions are changed through the handle they were checked on, so a link put anywhere in the path since can't send the change to another file. And the row is hidden by the folder being the trash, known at once, rather than by the note read later, which showed it for a moment and kept it for what's inside a trashed folder. Co-Authored-By: Claude Opus 5.5 --- src/PreviewPane.qml | 2 +- src/backend.cpp | 17 ++++++++++++++--- src/fileops.cpp | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/PreviewPane.qml b/src/PreviewPane.qml index 527f3b98..e28dcc55 100644 --- a/src/PreviewPane.qml +++ b/src/PreviewPane.qml @@ -269,7 +269,7 @@ Rectangle { // row keeps its place while they're read, so moving through files // doesn't shift the rows below it. Not in the trash, where nothing // changes them. - readonly property bool permissionsShown: pane.hasItem && !pane.trashed && !pane.pluginItem + readonly property bool permissionsShown: pane.hasItem && !(pane.folderPane && pane.folderPane.inTrash) && !pane.pluginItem && pane.item.path.startsWith("/") FolioText { visible: parent.permissionsShown; text: qsTr("Permissions"); color: theme.secondaryForeground; size: 12 } FolioText { diff --git a/src/backend.cpp b/src/backend.cpp index 5c8c6186..a1012b82 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -495,10 +496,20 @@ void Backend::describe(const QVariantMap &item, bool inTrash) { }); // Stepping through files faster than they're read queues readings; the // ones overtaken before they start are skipped rather than left to tie - // up the global pool's threads. A file its extension could not name has - // its type read from what it holds. + // up the threads the next folder is listed on. + // Every local item is read now (its permissions at least), so the + // readings get a few threads of their own: moving across folders on a + // mount that stopped answering leaves reads stuck, and in the shared + // pool they'd keep any folder from being listed. Never torn down, so a + // stuck one can't keep Folio from quitting either. A file its extension + // could not name has its type read from what it holds. + static QThreadPool *const reading = [] { + auto *pool = new QThreadPool; + pool->setMaxThreadCount(4); + return pool; + }(); const bool unnamed = mime == "application/octet-stream"; - watcher->setFuture(QtConcurrent::run([path, kind, mime, unnamed, inTrash, latest = m_describing, generation] { + watcher->setFuture(QtConcurrent::run(reading, [path, kind, mime, unnamed, inTrash, latest = m_describing, generation] { QVariantMap read; if (*latest != generation) return read; diff --git a/src/fileops.cpp b/src/fileops.cpp index df2db47e..25edaa61 100644 --- a/src/fileops.cpp +++ b/src/fileops.cpp @@ -1063,18 +1063,27 @@ bool FileOps::executable(const QStringList &paths) const { void FileOps::setExecutable(const QStringList &paths, bool on) { QStringList changed, failures; for (const QString &path : paths) { + // Looked at and changed through one handle, so a link put anywhere + // in the path after the menu opened can't send the change elsewhere. + const int fd = ::open(QFile::encodeName(path).constData(), O_PATH | O_NOFOLLOW | O_CLOEXEC); struct stat st; - if (!ownFile(path, &st)) + if (fd < 0 || ::fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_uid != ::geteuid()) { + if (fd >= 0) + ::close(fd); continue; + } // Whoever may read it may run it, so a file kept private stays so; // off, no one may. const mode_t read = st.st_mode & (S_IRUSR | S_IRGRP | S_IROTH); const mode_t mode = on ? (st.st_mode | read >> 2) : (st.st_mode & ~(S_IXUSR | S_IXGRP | S_IXOTH)); - // Never through a link put there since it was looked at. - if (::fchmodat(AT_FDCWD, QFile::encodeName(path).constData(), mode & 07777, AT_SYMLINK_NOFOLLOW) == 0) + // fchmod() can't take an O_PATH handle; its /proc link can be changed. + const bool done = ::chmod(("/proc/self/fd/" + QByteArray::number(fd)).constData(), mode & 07777) == 0; + const int why = errno; + ::close(fd); + if (done) changed << path; else - failures << tr("%1 (%2)").arg(QFileInfo(path).fileName(), QString::fromLocal8Bit(strerror(errno))); + failures << tr("%1 (%2)").arg(QFileInfo(path).fileName(), QString::fromLocal8Bit(strerror(why))); } if (!changed.isEmpty()) emit modesChanged(changed); From d03b28ad5e4efdfa1e8676d48bec448080b9a08e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 16:13:54 +0100 Subject: [PATCH 3/4] Say why a file gone since the menu opened couldn't be made executable A selected file moved away, or whose folder went out of reach, after the menu opened was skipped without a word, while a failed chmod said why. Now both say why; a folder, link or someone else's file is still left alone quietly, as the menu never offered them. Co-Authored-By: Claude Opus 5.5 --- src/fileops.cpp | 14 ++++++++++++-- tests/folio_tests.cpp | 7 +++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/fileops.cpp b/src/fileops.cpp index 25edaa61..3f8739f8 100644 --- a/src/fileops.cpp +++ b/src/fileops.cpp @@ -1062,16 +1062,26 @@ bool FileOps::executable(const QStringList &paths) const { void FileOps::setExecutable(const QStringList &paths, bool on) { QStringList changed, failures; + const auto fail = [&](const QString &path, int why) { + failures << tr("%1 (%2)").arg(QFileInfo(path).fileName(), QString::fromLocal8Bit(strerror(why))); + }; for (const QString &path : paths) { // Looked at and changed through one handle, so a link put anywhere // in the path after the menu opened can't send the change elsewhere. const int fd = ::open(QFile::encodeName(path).constData(), O_PATH | O_NOFOLLOW | O_CLOEXEC); struct stat st; - if (fd < 0 || ::fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_uid != ::geteuid()) { + // One gone or out of reach since the menu opened says why; a + // folder, link or someone else's file is just left alone. + if (fd < 0 || ::fstat(fd, &st) != 0) { + fail(path, errno); if (fd >= 0) ::close(fd); continue; } + if (!S_ISREG(st.st_mode) || st.st_uid != ::geteuid()) { + ::close(fd); + continue; + } // Whoever may read it may run it, so a file kept private stays so; // off, no one may. const mode_t read = st.st_mode & (S_IRUSR | S_IRGRP | S_IROTH); @@ -1083,7 +1093,7 @@ void FileOps::setExecutable(const QStringList &paths, bool on) { if (done) changed << path; else - failures << tr("%1 (%2)").arg(QFileInfo(path).fileName(), QString::fromLocal8Bit(strerror(why))); + fail(path, why); } if (!changed.isEmpty()) emit modesChanged(changed); diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index f3372d90..bc24e132 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -1456,6 +1456,13 @@ private slots: ops.setExecutable({script, secret}, false); QCOMPARE(mode(script), 0644u); QCOMPARE(mode(secret), 0600u); + + // A file gone since the menu opened says so; the folder beside it + // is still left alone without a word. + QSignalSpy failed(&ops, &FileOps::failed); + ops.setExecutable({dir.filePath("gone.sh"), folder}, true); + QCOMPARE(failed.count(), 1); + QVERIFY(failed.at(0).at(0).toString().contains("gone.sh")); } void fileOpsDeleteForeverOutsideTheTrash() From 20169c211e666f0c087a97f872c09266eac445ea Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 16:37:51 +0100 Subject: [PATCH 4/4] Change no file's mode while other work is under way Make Executable ran while the pane was copying, so a file still being copied could have its execute bits taken off, and then the copy, once done, gave it its source's mode again without a word. It now waits for the work under way like every other change to files, and says so. Co-Authored-By: Claude Opus 5.5 --- src/fileops.cpp | 3 +++ tests/folio_tests.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/fileops.cpp b/src/fileops.cpp index 3f8739f8..9b6a087e 100644 --- a/src/fileops.cpp +++ b/src/fileops.cpp @@ -1061,6 +1061,9 @@ bool FileOps::executable(const QStringList &paths) const { } void FileOps::setExecutable(const QStringList &paths, bool on) { + // A copy still being written takes its source's mode once it's done. + if (paths.isEmpty() || !idle()) + return; QStringList changed, failures; const auto fail = [&](const QString &path, int why) { failures << tr("%1 (%2)").arg(QFileInfo(path).fileName(), QString::fromLocal8Bit(strerror(why))); diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index bc24e132..1143948c 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -1463,6 +1463,16 @@ private slots: ops.setExecutable({dir.filePath("gone.sh"), folder}, true); QCOMPARE(failed.count(), 1); QVERIFY(failed.at(0).at(0).toString().contains("gone.sh")); + + // Not while other work is under way: a copy still being written + // would put its source's mode back once it's done. + ops.trash({dir.filePath("gone.txt")}); + QVERIFY(!ops.busy().isEmpty()); + ops.setExecutable({script}, true); + QCOMPARE(failed.count(), 2); + QCOMPARE(failed.last().first().toString(), QString("Try again once the work under way is done.")); + QCOMPARE(mode(script), 0644u); + QTRY_VERIFY(ops.busy().isEmpty()); } void fileOpsDeleteForeverOutsideTheTrash()