better error message for user when deleting local items

we might be displaying too technical errors that the user will have no
way to understand

for example on macOS, we might be getting:
Unknown error: 513

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2025-04-04 16:37:47 +02:00
parent 2c78036e46
commit aac1e60a23
No known key found for this signature in database
GPG Key ID: 7D0F74F05C22F553
2 changed files with 9 additions and 14 deletions

View File

@ -58,18 +58,15 @@ QByteArray localFileIdFromFullId(const QByteArray &id)
bool PropagateLocalRemove::removeRecursively(const QString &path)
{
QString absolute = propagator()->fullLocalPath(_item->_file + path);
QStringList errors;
QList<QPair<QString, bool>> deleted;
const auto fileInfo = QFileInfo{absolute};
const auto parentFolderPath = fileInfo.dir().absolutePath();
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
bool success = FileSystem::removeRecursively(
absolute,
[&deleted](const QString &path, bool isDir) {
// by prepending, a folder deletion may be followed by content deletions
deleted.prepend(qMakePair(path, isDir));
},
&errors);
const auto success = FileSystem::removeRecursively(absolute,
[&deleted](const QString &path, bool isDir) {
// by prepending, a folder deletion may be followed by content deletions
deleted.prepend(qMakePair(path, isDir));
});
if (!success) {
// We need to delete the entries from the database now from the deleted vector.
@ -87,8 +84,6 @@ bool PropagateLocalRemove::removeRecursively(const QString &path)
qCWarning(lcPropagateLocalRemove) << "Failed to delete file record from local DB" << it.first.mid(propagator()->localPath().size());
}
}
_error = errors.join(", ");
}
return success;
}
@ -116,13 +111,13 @@ void PropagateLocalRemove::start()
if (_moveToTrash && propagator()->syncOptions()._vfs->mode() != OCC::Vfs::WindowsCfApi) {
if ((QDir(filename).exists() || FileSystem::fileExists(filename))
&& !FileSystem::moveToTrash(filename, &removeError)) {
done(SyncFileItem::NormalError, removeError, ErrorCategory::GenericError);
done(SyncFileItem::NormalError, tr("Temporary error when removing local item removed from server."), ErrorCategory::GenericError);
return;
}
} else {
if (_item->isDirectory()) {
if (QDir(filename).exists() && !removeRecursively(QString())) {
done(SyncFileItem::NormalError, _error, ErrorCategory::GenericError);
done(SyncFileItem::NormalError, tr("Temporary error when removing local item removed from server."), ErrorCategory::GenericError);
return;
}
} else {
@ -133,7 +128,7 @@ void PropagateLocalRemove::start()
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
if (!FileSystem::remove(filename, &removeError)) {
done(SyncFileItem::NormalError, removeError, ErrorCategory::GenericError);
done(SyncFileItem::NormalError, tr("Temporary error when removing local item removed from server."), ErrorCategory::GenericError);
return;
}
}

View File

@ -44,7 +44,7 @@ public:
private:
bool removeRecursively(const QString &path);
QString _error;
bool _moveToTrash = false;
};