From 3e4d9ca10c33746cb545e930886491e6a1227e6e Mon Sep 17 00:00:00 2001
From: Vladislav Kachegov <vladkachegov@gmail.com>
Date: Fri, 23 May 2025 12:46:54 +0300
Subject: [PATCH] fix incorrect view reset when unmounting similarly-named
 devices

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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 297ab000e8..2697b12fb8 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -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()));
         }
     }
-- 
GitLab

