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 <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2021-11-22 13:25:55 +01:00 committed by Matthieu Gallien (Rebase PR Action)
parent 9eed62a854
commit a3013de6ea

View 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);