From a3013de6ea69287eab5d1fd9bf54be69ed54c982 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 22 Nov 2021 13:25:55 +0100 Subject: [PATCH] fix OCC::CfApiWrapper::handleForPath when path does not exist 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 --- src/libsync/vfs/cfapi/cfapiwrapper.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index a5d947aa4..0469d9ec5 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -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); -- 2.30.2