Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle file lock during delete #9295

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog/unreleased/9293
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Bugfix: Handle file locks for delete jobs

We no longer report an error when the client tries to delete a locked file
but wait for the lock to be removed.

This only works when a file is deleted not on folders.

https://github.com/owncloud/client/issues/9293
https://github.com/owncloud/client/pull/9295
3 changes: 1 addition & 2 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ bool FileSystem::fileExists(const QString &filename, const QFileInfo &fileInfo)
// not valid. There needs to be one initialised here. Otherwise the incoming
// fileInfo is re-used.
if (fileInfo.filePath() != filename) {
QFileInfo myFI(filename);
re = myFI.exists();
re = QFileInfo::exists(filename);
}
return re;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateuploadng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void PropagateUploadFileNG::doStartUpload()
const auto lockMode = propagator()->syncOptions().requiredLockMode();
if (FileSystem::isFileLocked(fileName, lockMode)) {
emit propagator()->seenLockedFile(fileName, lockMode);
abortWithError(SyncFileItem::SoftError, tr("%1 the file is currently in use").arg(fileName));
abortWithError(SyncFileItem::SoftError, tr("%1 the file is currently in use").arg(QDir::toNativeSeparators(fileName)));
return;
}

Expand Down
39 changes: 21 additions & 18 deletions src/libsync/propagatorjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ Q_LOGGING_CATEGORY(lcPropagateLocalRename, "sync.propagator.localrename", QtInfo
*
* \a path is relative to propagator()->_localDir + _item->_file and should start with a slash
*/
bool PropagateLocalRemove::removeRecursively(const QString &path)
bool PropagateLocalRemove::removeRecursively(const QString &absolute, QString *error)
{
QString absolute = propagator()->fullLocalPath(_item->_file + path);
QStringList errors;
// path, isDir
QList<QPair<QString, bool>> deleted;
bool success = FileSystem::removeRecursively(
absolute,
Expand All @@ -75,7 +75,7 @@ bool PropagateLocalRemove::removeRecursively(const QString &path)
propagator()->_journal->deleteFileRecord(it.first.mid(propagator()->localPath().size()), it.second);
}

_error = errors.join(QStringLiteral(", "));
*error = errors.join(QStringLiteral(", "));
}
return success;
}
Expand All @@ -95,26 +95,29 @@ void PropagateLocalRemove::start()
return;
}

QString removeError;
if (_moveToTrash) {
if ((QDir(filename).exists() || FileSystem::fileExists(filename))
&& !FileSystem::moveToTrash(filename, &removeError)) {
done(SyncFileItem::NormalError, removeError);
if (FileSystem::fileExists(filename)) {
bool ok;
QString removeError;
const auto lockMode = propagator()->syncOptions().requiredLockMode();
if (FileSystem::isFileLocked(filename, lockMode)) {
emit propagator()->seenLockedFile(filename, lockMode);
done(SyncFileItem::SoftError, tr("%1 the file is currently in use").arg(QDir::toNativeSeparators(filename)));
return;
}
} else {
if (_item->isDirectory()) {
if (QDir(filename).exists() && !removeRecursively(QString())) {
done(SyncFileItem::NormalError, _error);
return;
}

if (_moveToTrash) {
ok = FileSystem::moveToTrash(filename, &removeError);
} else {
if (FileSystem::fileExists(filename)
&& !FileSystem::remove(filename, &removeError)) {
done(SyncFileItem::NormalError, removeError);
return;
if (_item->isDirectory()) {
ok = removeRecursively(filename, &removeError);
} else {
ok = FileSystem::remove(filename, &removeError);
}
}
if (!ok) {
done(SyncFileItem::NormalError, removeError);
return;
}
}
propagator()->reportProgress(*_item, 0);
propagator()->_journal->deleteFileRecord(_item->_originalFile, _item->isDirectory());
Expand Down
3 changes: 1 addition & 2 deletions src/libsync/propagatorjobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class PropagateLocalRemove : public PropagateItemJob
void start() override;

private:
bool removeRecursively(const QString &path);
QString _error;
bool removeRecursively(const QString &absolute, QString *error);
bool _moveToTrash;
};

Expand Down