]> cloud.milkyroute.net Git - dolphin.git/commitdiff
fix incorrect view reset when unmounting similarly-named devices
authorVladislav Kachegov <vladkachegov@gmail.com>
Fri, 23 May 2025 09:46:54 +0000 (12:46 +0300)
committerFelix Ernst <felixernst@kde.org>
Sat, 31 May 2025 22:58:47 +0000 (00:58 +0200)
Previously, unmounting a device would incorrectly reset views containing:
- Paths with similar names (e.g. "/media/disk" and "/media/disk_2")
- Substrings of the mounted path

Now only resets views showing either:
1. The exact mounted path (e.g. "/media/disk")
2. Its subdirectories (e.g. "/media/disk/docs")

src/dolphinmainwindow.cpp

index 297ab000e80b8e9c79777889aa01e7dcb0742d8d..2697b12fb85334c9e31cadb4cf26875ed810edd5 100644 (file)
@@ -1726,7 +1726,11 @@ void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString &mountPath)
 {
     const QVector<DolphinViewContainer *> theViewContainers = viewContainers();
     for (DolphinViewContainer *viewContainer : theViewContainers) {
-        if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
+        if (!viewContainer) {
+            continue;
+        }
+        const auto viewPath = viewContainer->url().toLocalFile();
+        if (viewPath.startsWith(mountPath + QLatin1String("/")) || viewPath == mountPath) {
             viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
         }
     }