[network/kio-extras] smb: smb: name a root "." and show what the reader knows it by

Méven Car <[email protected]> Tue, 4 Aug 2026 13:36:18 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 53d75b82556d88e16d759761c97a3c1ef0d78ece by Méven Car.
Committed on 04/08/2026 at 13:25.
Pushed by meven into branch 'master'.

smb: name a root "." and show what the reader knows it by

The network and the root of a host carry their name in the authority of their
url, so the name stat took from the url was empty for both, where a directory is
named "." for itself, as listing one already says. Stat now says the same as the
listing does.

Neither has anything a reader would recognise then, so both carry what the url
says they are in UDS_DISPLAY_NAME, the host, the workgroup, or the name the
shares are already listed under in the network folder.

M  +27   -3    smb/kio_smb_browse.cpp

https://invent.kde.org/network/kio-extras/-/commit/53d75b82556d88e16d759761c97a3c1ef0d78ece

diff --git a/smb/kio_smb_browse.cpp b/smb/kio_smb_browse.cpp
index 3fe954965..f35777f99 100644
--- a/smb/kio_smb_browse.cpp
+++ b/smb/kio_smb_browse.cpp
@@ -18,6 +18,7 @@
 
 #include <QEventLoop>
 #include <QTimer>
+#include <QUrlQuery>
 
 #include <grp.h>
 #include <pwd.h>
@@ -29,6 +30,21 @@
 
 using namespace KIO;
 
+static QString displayNameForUrl(const QUrl &url)
+{
+    const QString name = url.fileName();
+    if (!name.isEmpty()) {
+        return name;
+    }
+
+    if (!url.host().isEmpty()) {
+        return url.host();
+    }
+
+    const QString workgroup = QUrlQuery(url).queryItemValue("kio-workgroup");
+    return workgroup.isEmpty() ? i18nc("@item the top of the shares that can be browsed", "Shared Folders (SMB)") : workgroup;
+}
+
 int SMBWorker::cache_stat(const SMBUrl &url, struct stat *st)
 {
     int cacheStatErr = 0;
@@ -134,7 +150,12 @@ WorkerResult SMBWorker::stat(const QUrl &kurl)
 
     UDSEntry udsentry;
     // Set name
-    udsentry.fastInsert(KIO::UDSEntry::UDS_NAME, kurl.fileName());
+    const QString name = kurl.fileName();
+    KIOExtras::insertStrings(udsentry,
+                             {
+                                 {KIO::UDSEntry::UDS_NAME, name.isEmpty() ? QStringLiteral(".") : name},
+                                 {KIO::UDSEntry::UDS_DISPLAY_NAME, displayNameForUrl(kurl)},
+                             });
 
     switch (m_current_url.getType()) {
     case SMBURLTYPE_UNKNOWN:
@@ -478,15 +499,18 @@ WorkerResult SMBWorker::listDir(const QUrl &kurl)
     }
 
     UDSEntry udsentry;
+    KIOExtras::insertStrings(udsentry,
+                             {
+                                 {KIO::UDSEntry::UDS_NAME, QStringLiteral(".")},
+                                 {KIO::UDSEntry::UDS_DISPLAY_NAME, displayNameForUrl(m_current_url)},
+                             });
     if (smbc->dirWasRoot()) {
-        udsentry.fastInsert(KIO::UDSEntry::UDS_NAME, ".");
         KIOExtras::insertNumbers(udsentry,
                                  {
                                      {KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR},
                                      {KIO::UDSEntry::UDS_ACCESS, (S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH)},
                                  });
     } else {
-        udsentry.fastInsert(KIO::UDSEntry::UDS_NAME, ".");
         const int statErr = browse_stat_path(m_current_url, udsentry);
         if (statErr != 0) {
             if (statErr == ENOENT || statErr == ENOTDIR) {