Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2021-06-21 14:28:40 +0300
committerHannah von Reth <vonreth@kde.org>2021-06-21 15:05:21 +0300
commit031d59ccce7c9a98946617031c9b1c7bc2262c9a (patch)
tree646b8728584a0d2ce56b44e139384877f7e75e34 /src/common
parent79d41c7a245e6162f79f362f3aa1263b2ecdec62 (diff)
Require exclusive locks for vfs and renames
Fixes: #8761
Diffstat (limited to 'src/common')
-rw-r--r--src/common/filesystembase.cpp12
-rw-r--r--src/common/filesystembase.h8
2 files changed, 17 insertions, 3 deletions
diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp
index d73ef4b86..8cb1b53dd 100644
--- a/src/common/filesystembase.cpp
+++ b/src/common/filesystembase.cpp
@@ -438,18 +438,19 @@ bool FileSystem::moveToTrash(const QString &fileName, QString *errorString)
#endif
}
-bool FileSystem::isFileLocked(const QString &fileName)
+bool FileSystem::isFileLocked(const QString &fileName, LockMode mode)
{
#ifdef Q_OS_WIN
// Check if file exists
const QString fName = longWinPath(fileName);
+ auto accessMode = mode == LockMode::Exclusive ? 0 : FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
DWORD attr = GetFileAttributesW(reinterpret_cast<const wchar_t *>(fName.utf16()));
if (attr != INVALID_FILE_ATTRIBUTES) {
// Try to open the file with as much access as possible..
HANDLE win_h = CreateFileW(
reinterpret_cast<const wchar_t *>(fName.utf16()),
GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ accessMode,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
NULL);
@@ -461,6 +462,11 @@ bool FileSystem::isFileLocked(const QString &fileName)
} else {
CloseHandle(win_h);
}
+ } else {
+ const auto error = GetLastError();
+ if (error != ERROR_FILE_NOT_FOUND && error != ERROR_PATH_NOT_FOUND) {
+ qCWarning(lcFileSystem()) << "GetFileAttributesW" << Utility::formatWinError(error);
+ }
}
#else
Q_UNUSED(fileName);
@@ -521,3 +527,5 @@ QString FileSystem::pathtoUNC(const QString &str)
}
} // namespace OCC
+
+#include "moc_filesystembase.cpp"
diff --git a/src/common/filesystembase.h b/src/common/filesystembase.h
index 4e3573058..3418ce63e 100644
--- a/src/common/filesystembase.h
+++ b/src/common/filesystembase.h
@@ -42,6 +42,7 @@ OCSYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcFileSystem)
* @brief This file contains file system helper
*/
namespace FileSystem {
+ OCSYNC_EXPORT Q_NAMESPACE;
/**
* @brief Mark the file as hidden (only has effects on windows)
@@ -130,10 +131,15 @@ namespace FileSystem {
QString fileSystemForPath(const QString &path);
#endif
+ enum class LockMode {
+ Shared,
+ Exclusive
+ };
+ Q_ENUM_NS(LockMode);
/**
* Returns true when a file is locked. (Windows only)
*/
- bool OCSYNC_EXPORT isFileLocked(const QString &fileName);
+ bool OCSYNC_EXPORT isFileLocked(const QString &fileName, LockMode mode);
/**
* Returns whether the file is a shortcut file (ends with .lnk)