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-22 10:26:23 +0300
committerHannah von Reth <vonreth@kde.org>2021-06-22 14:54:56 +0300
commit650be8b0d8d812f73ff2f117a253ae1ff5e3afe1 (patch)
treef22e622b3a0070a0e43a45a7b62506a32ce72618 /src/common
parente78ce41e46ad8a005bee5b818870a14f262bb8b6 (diff)
Check a wehter file is locked before we move
Fixes: #8765, #8766
Diffstat (limited to 'src/common')
-rw-r--r--src/common/filesystembase.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp
index 8cb1b53dd..4ae24c870 100644
--- a/src/common/filesystembase.cpp
+++ b/src/common/filesystembase.cpp
@@ -133,10 +133,13 @@ bool FileSystem::rename(const QString &originFileName,
bool success = false;
QString error;
#ifdef Q_OS_WIN
- QString orig = longWinPath(originFileName);
- QString dest = longWinPath(destinationFileName);
-
- if (isLnkFile(originFileName) || isLnkFile(destinationFileName)) {
+ const QString orig = longWinPath(originFileName);
+ const QString dest = longWinPath(destinationFileName);
+ if (FileSystem::isFileLocked(dest, FileSystem::LockMode::Exclusive)) {
+ error = QCoreApplication::translate("FileSystem", "Can't rename %1, the file is currently in use").arg(destinationFileName);
+ } else if (FileSystem::isFileLocked(orig, FileSystem::LockMode::Exclusive)) {
+ error = QCoreApplication::translate("FileSystem", "Can't rename %1, the file is currently in use").arg(originFileName);
+ } else if (isLnkFile(originFileName) || isLnkFile(destinationFileName)) {
success = MoveFileEx((wchar_t *)orig.utf16(),
(wchar_t *)dest.utf16(),
MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH);
@@ -168,6 +171,7 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName,
const QString &destinationFileName,
QString *errorString)
{
+ Q_ASSERT(errorString);
#ifndef Q_OS_WIN
bool success;
QFile orig(originFileName);
@@ -195,13 +199,20 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName,
if (!QFileInfo(destinationFileName).isWritable()) {
setFileReadOnly(destinationFileName, false);
}
-
- BOOL ok;
- QString orig = longWinPath(originFileName);
- QString dest = longWinPath(destinationFileName);
-
- ok = MoveFileEx((wchar_t *)orig.utf16(),
- (wchar_t *)dest.utf16(),
+ const QString orig = longWinPath(originFileName);
+ const QString dest = longWinPath(destinationFileName);
+ if (FileSystem::isFileLocked(dest, FileSystem::LockMode::Exclusive)) {
+ *errorString = QCoreApplication::translate("FileSystem", "Can't rename %1, the file is currently in use").arg(destinationFileName);
+ qCWarning(lcFileSystem) << "Renaming failed: " << *errorString;
+ return false;
+ }
+ if (FileSystem::isFileLocked(orig, FileSystem::LockMode::Exclusive)) {
+ *errorString = QCoreApplication::translate("FileSystem", "Can't rename %1, the file is currently in use").arg(originFileName);
+ qCWarning(lcFileSystem) << "Renaming failed: " << *errorString;
+ return false;
+ }
+ const BOOL ok = MoveFileEx(reinterpret_cast<const wchar_t *>(orig.utf16()),
+ reinterpret_cast<const wchar_t *>(dest.utf16()),
MOVEFILE_REPLACE_EXISTING + MOVEFILE_COPY_ALLOWED + MOVEFILE_WRITE_THROUGH);
if (!ok) {
*errorString = Utility::formatWinError(GetLastError());