From 9eed62a85465e87c20603e13f3cd7ad2e135ab83 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 22 Nov 2021 13:24:50 +0100 Subject: [PATCH 1/4] remove too noisy log print Signed-off-by: Matthieu Gallien --- src/libsync/vfs/cfapi/cfapiwrapper.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index 8046cb18a4..a5d947aa40 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -618,7 +618,6 @@ OCC::CfApiWrapper::PlaceHolderInfo OCC::CfApiWrapper::findPlaceholderInfo(const if (result == S_OK) { return info; } else { - qCWarning(lcCfApiWrapper()) << "Couldn't get placeholder info" << QString::fromWCharArray(_com_error(result).ErrorMessage()); return {}; } } From a3013de6ea69287eab5d1fd9bf54be69ed54c982 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 22 Nov 2021 13:25:55 +0100 Subject: [PATCH 2/4] 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 a5d947aa40..0469d9ec5a 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); From 072e9d44bd1792e7aa1e91ff0b5e36804a463a46 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 22 Nov 2021 13:27:00 +0100 Subject: [PATCH 3/4] gracefully handle one case of invalid handles Signed-off-by: Matthieu Gallien --- src/libsync/vfs/cfapi/vfs_cfapi.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libsync/vfs/cfapi/vfs_cfapi.cpp b/src/libsync/vfs/cfapi/vfs_cfapi.cpp index 76e3c446d5..1adeb5d686 100644 --- a/src/libsync/vfs/cfapi/vfs_cfapi.cpp +++ b/src/libsync/vfs/cfapi/vfs_cfapi.cpp @@ -160,6 +160,9 @@ Result VfsCfApi::convertToPlaceholder( const auto replacesPath = QDir::toNativeSeparators(replacesFile); const auto handle = cfapi::handleForPath(localPath); + if (!handle) { + return { "Invalid handle for path " + localPath }; + } if (cfapi::findPlaceholderInfo(handle)) { return cfapi::updatePlaceholderInfo(handle, item._modtime, item._size, item._fileId, replacesPath); } else { From 83a8058b511cbb2f521a316840a1736dc2dde907 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 22 Nov 2021 13:28:58 +0100 Subject: [PATCH 4/4] improve logging for CfApi Signed-off-by: Matthieu Gallien --- src/libsync/vfs/cfapi/cfapiwrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index 0469d9ec5a..525ba7c9c3 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -713,7 +713,7 @@ OCC::Result OCC::CfApiWrapper::up nullptr, 0, CF_UPDATE_FLAG_MARK_IN_SYNC, nullptr, nullptr); if (result != S_OK) { - qCWarning(lcCfApiWrapper) << "Couldn't update placeholder info for" << pathForHandle(handle) << ":" << QString::fromWCharArray(_com_error(result).ErrorMessage()); + qCWarning(lcCfApiWrapper) << "Couldn't update placeholder info for" << pathForHandle(handle) << ":" << QString::fromWCharArray(_com_error(result).ErrorMessage()) << replacesPath; return { "Couldn't update placeholder info" }; }