From 06b95932d24b2d6d1f95b8d1d264edf90a567955 Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 18 Nov 2026 16:02:47 +0100 Subject: [PATCH] Mount NFS, FTPS and \\server\share addresses The path bar now also takes nfs://, ftps:// and Windows \\server\share paths, and the ssh://, cifs://, webdav:// and webdavs:// spellings of the schemes it already mounts. An NFS address without its export, or an address with a password in it, says what to change instead of failing in GVfs. Co-Authored-By: Claude Opus 5.5 --- src/backend.cpp | 48 ++++++++++++++++++++++++++++++++++++++----- src/backend.h | 8 +++++--- src/i18n/en.json | 2 ++ tests/folio_tests.cpp | 30 +++++++++++++++++++++++++-- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index 878f98ba..a08b962c 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -389,13 +389,46 @@ void Backend::arrive(const QString &folder) { showItem(target.filePath()); } -QString Backend::serverAddress(const QString &text) { - static const QStringList schemes{"sftp", "smb", "ftp", "dav", "davs"}; +QString Backend::serverAddress(const QString &text, QString *problem) { + if (problem) + problem->clear(); + const QString raw = text.trimmed(); + static const QStringList schemes{"sftp", "smb", "nfs", "ftp", "ftps", "dav", "davs"}; // Tolerant, so a path typed with spaces in it is escaped rather than - // refused; QUrl puts the scheme in lower case. - QUrl url(text.trimmed(), QUrl::TolerantMode); + // refused; QUrl puts the scheme in lower case. A Windows UNC path has no + // query or fragment, so its folder names are set decoded. + QUrl url; + if (raw.startsWith("\\\\")) { + const QString unc = raw.mid(2).replace('\\', '/'); + url.setScheme("smb"); + url.setHost(unc.section('/', 0, 0)); + const QString rest = unc.section('/', 1); + url.setPath(rest.isEmpty() ? "/" : "/" + rest, QUrl::DecodedMode); + } else { + url = QUrl(raw, QUrl::TolerantMode); + } + if (url.scheme() == "ssh") + url.setScheme("sftp"); + else if (url.scheme() == "cifs") + url.setScheme("smb"); + else if (url.scheme() == "webdav") + url.setScheme("dav"); + else if (url.scheme() == "webdavs") + url.setScheme("davs"); if (!url.isValid() || !schemes.contains(url.scheme()) || url.host().isEmpty()) return {}; + if (!url.password().isEmpty()) { + if (problem) + *problem = tr("Leave the password out of the address; enter it when asked to sign in."); + return {}; + } + // A Windows host on its own is fine (its shares are offered to pick + // from), but an NFS server has no such list. + if (url.scheme() == "nfs" && url.path().section('/', 0, 0, QString::SectionSkipEmpty).isEmpty()) { + if (problem) + *problem = tr("Add the exported folder, as in nfs://%1/export.").arg(url.host()); + return {}; + } if (url.path().isEmpty()) url.setPath("/"); return url.toString(QUrl::FullyEncoded); @@ -608,11 +641,16 @@ bool Backend::goTyped(const QString &text) { // A server is mounted through GVfs, which also says where on the mount // the address's path is (a WebDAV address's path can be part of the // mount itself), and connecting goes there. - if (const QString address = serverAddress(text); !address.isEmpty()) { + QString problem; + if (const QString address = serverAddress(text, &problem); !address.isEmpty()) { if (!m_mounter.busy()) mount(address, QUrl(address).host(), false); return true; } + if (!problem.isEmpty()) { + setMessage(problem); + return false; + } // A view is typed as the path bar shows it, by its own name. if (const QString view = text.trimmed(); FolderModel::isView(view)) return go(view, true); diff --git a/src/backend.h b/src/backend.h index 4e5ea958..83af0a54 100644 --- a/src/backend.h +++ b/src/backend.h @@ -134,9 +134,11 @@ class Backend : public QObject { static QString expandTyped(const QString &text, const QString &home, const QString ¤t); static QString complete(const QString &text, const QString &home, const QString ¤t); static QString mountLabel(const QString &mountFolder); - // A server address (sftp://, smb://, ftp://, dav://, davs://) as GIO - // mounts it, or empty when the text isn't one. - static QString serverAddress(const QString &text); + // A server address (sftp://, smb://, nfs://, ftp://, ftps://, dav://, + // davs://, or \\server\share) as GIO mounts it, or empty when the text + // isn't one. `problem` says why when it's an address that can't be + // mounted as written. + static QString serverAddress(const QString &text, QString *problem = nullptr); signals: void sortsChanged(); diff --git a/src/i18n/en.json b/src/i18n/en.json index c2bd349a..b27e3cc8 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -45,6 +45,7 @@ "A name can't contain \"/\".": "A name can't contain \"/\".", "A screenful up or down": "A screenful up or down", "Add or remove one": "Add or remove one", + "Add the exported folder, as in nfs://%1/export.": "Add the exported folder, as in nfs://%1/export.", "Archive": "Archive", "Back / ahead 5 seconds": "Back / ahead 5 seconds", "Back / forward": "Back / forward", @@ -217,6 +218,7 @@ "Keep Both": "Keep Both", "Keyboard shortcuts": "Keyboard shortcuts", "Kind": "Kind", + "Leave the password out of the address; enter it when asked to sign in.": "Leave the password out of the address; enter it when asked to sign in.", "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.", diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 6a0aeeb4..c92e24c2 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -4480,6 +4480,7 @@ private slots: QCOMPARE(Backend::mountLabel("sftp:host=studio.example.ts.net,user=me"), QString("studio.example.ts.net")); QCOMPARE(Backend::mountLabel("sftp:host=files.example.com"), QString("files.example.com")); QCOMPARE(Backend::mountLabel("smb-share:server=nas,share=media"), QString("nas")); + QCOMPARE(Backend::mountLabel("nfs:host=nas,prefix=%2Fsrv%2Fexport"), QString("nas")); QCOMPARE(Backend::mountLabel("ftp:host=ftp.example.com"), QString("ftp.example.com")); QCOMPARE(Backend::mountLabel("dav:host=cloud.example.com,ssl=true,prefix=%2Fremote.php"), QString("cloud.example.com")); } @@ -4491,14 +4492,39 @@ private slots: // the mount itself. QCOMPARE(Backend::serverAddress("sftp://nas"), QString("sftp://nas/")); QCOMPARE(Backend::serverAddress(" SFTP://me@nas:2222/srv/My Files "), QString("sftp://me@nas:2222/srv/My%20Files")); + QCOMPARE(Backend::serverAddress("ssh://me@nas:2222/srv"), QString("sftp://me@nas:2222/srv")); QCOMPARE(Backend::serverAddress("smb://nas/media/Films"), QString("smb://nas/media/Films")); + QCOMPARE(Backend::serverAddress("smb://nas"), QString("smb://nas/")); + QCOMPARE(Backend::serverAddress("cifs://nas/media"), QString("smb://nas/media")); + QCOMPARE(Backend::serverAddress("\\\\nas"), QString("smb://nas/")); + QCOMPARE(Backend::serverAddress("\\\\nas\\media\\Films"), QString("smb://nas/media/Films")); + QCOMPARE(Backend::serverAddress("\\\\nas\\media\\Project#1"), QString("smb://nas/media/Project%231")); + QCOMPARE(Backend::serverAddress("nfs://nas/srv/export"), QString("nfs://nas/srv/export")); QCOMPARE(Backend::serverAddress("ftp://ftp.example.com/pub/"), QString("ftp://ftp.example.com/pub/")); + QCOMPARE(Backend::serverAddress("ftps://ftp.example.com/pub/"), QString("ftps://ftp.example.com/pub/")); QCOMPARE(Backend::serverAddress("davs://cloud.example.com/remote.php/dav/files/me"), QString("davs://cloud.example.com/remote.php/dav/files/me")); + QCOMPARE(Backend::serverAddress("webdavs://cloud.example.com/dav"), QString("davs://cloud.example.com/dav")); + QCOMPARE(Backend::serverAddress("webdav://10.0.0.5:8080"), QString("dav://10.0.0.5:8080/")); QCOMPARE(Backend::serverAddress("dav://10.0.0.5:8080"), QString("dav://10.0.0.5:8080/")); // Paths, other schemes and addresses without a server are not. - for (const char *text : {"~/Work", "/etc", "Work/folio", "file:///etc", "http://example.com", "sftp://", "smb:/nas"}) - QVERIFY2(Backend::serverAddress(text).isEmpty(), text); + for (const char *text : {"~/Work", "/etc", "Work/folio", "file:///etc", "http://example.com", "sftp://", "smb:/nas", "\\\\"}) { + QString problem; + QVERIFY2(Backend::serverAddress(text, &problem).isEmpty(), text); + QVERIFY2(problem.isEmpty(), text); + } + + // An address that needs an export, or embeds a password, is refused + // with the reason why, and goTyped shows that reason. + QTemporaryDir home; + Backend backend(home.path()); + for (const char *incomplete : {"nfs://nas", "nfs://nas/", "sftp://me:secret@nas/"}) { + QString problem; + QVERIFY2(Backend::serverAddress(incomplete, &problem).isEmpty(), incomplete); + QVERIFY2(!problem.isEmpty(), incomplete); + QVERIFY(!backend.goTyped(incomplete)); + QCOMPARE(backend.message(), problem); + } } void pluginsReadTheirManifests()