fix OCC::CfApiWrapper::handleForPath when path does not exist
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 22 Nov 2021 12:25:55 +0000 (13:25 +0100)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Tue, 23 Nov 2021 13:41:29 +0000 (13:41 +0000)
sometime it can be called with a path that is already deleted

ensure we always go to the correct code path

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/vfs/cfapi/cfapiwrapper.cpp

index a5d947aa4077f2b488f180d1521651bd916595d7..0469d9ec5ad1e1fe6063f4cecb8b0ee99c1f05b9 100644 (file)
@@ -586,13 +586,18 @@ OCC::CfApiWrapper::FileHandle OCC::CfApiWrapper::handleForPath(const QString &pa
         return {};
     }
 
-    if (QFileInfo(path).isDir()) {
+    QFileInfo pathFileInfo(path);
+    if (!pathFileInfo.exists()) {
+        return {};
+    }
+
+    if (pathFileInfo.isDir()) {
         HANDLE handle = nullptr;
         const qint64 openResult = CfOpenFileWithOplock(path.toStdWString().data(), CF_OPEN_FILE_FLAG_NONE, &handle);
         if (openResult == S_OK) {
             return {handle, [](HANDLE h) { CfCloseHandle(h); }};
         }
-    } else {
+    } else if (pathFileInfo.isFile()) {
         const auto longpath = OCC::FileSystem::longWinPath(path);
         const auto handle = CreateFile(longpath.toStdWString().data(), 0, 0, nullptr,
                                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);