]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[ViewProperties] Check part of home first before doing file system stuff
authorKai Uwe Broulik <kde@privat.broulik.de>
Mon, 17 Sep 2018 14:02:50 +0000 (16:02 +0200)
committerKai Uwe Broulik <kde@privat.broulik.de>
Mon, 17 Sep 2018 14:02:50 +0000 (16:02 +0200)
There's no point in creating a QFileInfo instance and checking for file properties if we're not going to do anything with it
when not inside home.

Differential Revision: https://phabricator.kde.org/D15237

src/views/viewproperties.cpp

index e5d636cd1e1626a51b421da2dbf51e49e34c5bd0..d7c6abd65ed9742bc3d4fa944fe62d150c823c73 100644 (file)
@@ -63,17 +63,19 @@ ViewProperties::ViewProperties(const QUrl& url) :
         useDetailsViewWithPath = true;
     } else if (url.isLocalFile()) {
         m_filePath = url.toLocalFile();
-        const QFileInfo dirInfo(m_filePath);
-        const QFileInfo fileInfo(m_filePath + QDir::separator() + ViewPropertiesFileName);
-        // Check if the directory is writable and check if the ".directory" file exists and
-        // is read- and writable.
-        if (!dirInfo.isWritable()
-                || (fileInfo.exists() && !(fileInfo.isReadable() && fileInfo.isWritable()))
-                || !isPartOfHome(m_filePath)) {
-#ifdef Q_OS_WIN
-                       // m_filePath probably begins with C:/ - the colon is not a valid character for paths though
-                       m_filePath =  QDir::separator() + m_filePath.remove(QLatin1Char(':'));
-#endif
+
+        bool useDestinationDir = !isPartOfHome(m_filePath);
+        if (!useDestinationDir) {
+            const QFileInfo dirInfo(m_filePath);
+            const QFileInfo fileInfo(m_filePath + QDir::separator() + ViewPropertiesFileName);
+            useDestinationDir = !dirInfo.isWritable() || (dirInfo.size() > 0 && fileInfo.exists() && !(fileInfo.isReadable() && fileInfo.isWritable()));
+        }
+
+        if (useDestinationDir) {
+    #ifdef Q_OS_WIN
+            // m_filePath probably begins with C:/ - the colon is not a valid character for paths though
+            m_filePath =  QDir::separator() + m_filePath.remove(QLatin1Char(':'));
+    #endif
             m_filePath = destinationDir(QStringLiteral("local")) + m_filePath;
         }
     } else {