Skip to content

Commit ce16030

Browse files
committed
fix(lockedFiles): check for locked files before opening them
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent 0e9013e commit ce16030

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/libsync/propagateuploadng.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,19 @@ void PropagateUploadFileNG::startNextChunk()
355355
}
356356

357357
const auto fileName = _fileToUpload._path;
358+
if (FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead)) {
359+
// If the file is currently locked, we want to retry the sync
360+
// when it becomes available again.
361+
emit propagator()->seenLockedFile(fileName);
362+
363+
// Soft error because this is likely caused by the user modifying his files while syncing
364+
abortWithError(SyncFileItem::FileLocked, tr("File is locked preventing syncing it", "Generic warning message when a locked file cannot be synced"));
365+
return;
366+
}
358367
auto device = std::make_unique<UploadDevice>(fileName, _sent, _currentChunkSize, &propagator()->_bandwidthManager);
359-
if (auto isLocked = FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead); isLocked || !device->open(QIODevice::ReadOnly)) {
368+
if (!device->open(QIODevice::ReadOnly)) {
360369
qCWarning(lcPropagateUploadNG) << "Could not prepare upload device: " << device->errorString();
361370

362-
// If the file is currently locked, we want to retry the sync
363-
// when it becomes available again.
364-
if (isLocked) {
365-
emit propagator()->seenLockedFile(fileName);
366-
}
367371
// Soft error because this is likely caused by the user modifying his files while syncing
368372
abortWithError(SyncFileItem::SoftError, device->errorString());
369373
return;

src/libsync/propagateuploadv1.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,21 @@ void PropagateUploadFileV1::startNextChunk()
134134
}
135135

136136
const QString fileName = _fileToUpload._path;
137+
if (FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead)) {
138+
emit propagator()->seenLockedFile(fileName);
139+
140+
// Soft error because this is likely caused by the user modifying his files while syncing
141+
abortWithError(SyncFileItem::FileLocked, tr("File is locked preventing syncing it", "Generic warning message when a locked file cannot be synced"));
142+
return;
143+
}
144+
137145
auto device = std::make_unique<UploadDevice>(
138146
fileName, chunkStart, currentChunkSize, &propagator()->_bandwidthManager);
139-
if (const auto isLocked = FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead); isLocked || !device->open(QIODevice::ReadOnly)) {
147+
if (!device->open(QIODevice::ReadOnly)) {
140148
qCWarning(lcPropagateUploadV1) << "Could not prepare upload device: " << device->errorString();
141149

142-
// If the file is currently locked, we want to retry the sync
143-
// when it becomes available again.
144-
if (isLocked) {
145-
emit propagator()->seenLockedFile(fileName);
146-
}
147150
// Soft error because this is likely caused by the user modifying his files while syncing
148-
abortWithError(isLocked ? SyncFileItem::FileLocked : SyncFileItem::SoftError, device->errorString());
151+
abortWithError(SyncFileItem::SoftError, device->errorString());
149152
return;
150153
}
151154

0 commit comments

Comments
 (0)