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

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Gallien <matthieu_gallien@yahoo.fr>2022-04-08 13:19:44 +0300
committerGitHub <noreply@github.com>2022-04-08 13:19:44 +0300
commite210a6f2f0fcef546adce6e8fdc430d7f3bdf701 (patch)
tree7fdfb2a8ba5c27c1a4b472741fd6a0b9ff396630
parentbedd88a4dc5be8e490d9f4a251681726331a7b97 (diff)
parent265601d85c43a76ef5ebfcd96ab89bfbaa5b9b23 (diff)
Merge pull request #4416 from nextcloud/backport/4399/stable-3.4
[stable-3.4] avoid deleting renamed file with spaces in name
-rw-r--r--src/libsync/discovery.cpp4
-rw-r--r--src/libsync/propagateremotemkdir.cpp13
-rw-r--r--src/libsync/propagateupload.cpp12
-rw-r--r--test/testlocaldiscovery.cpp10
4 files changed, 39 insertions, 0 deletions
diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp
index a7e41d8bc..63b75a05f 100644
--- a/src/libsync/discovery.cpp
+++ b/src/libsync/discovery.cpp
@@ -1054,6 +1054,10 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
if (!localEntry.renameName.isEmpty()) {
handleInvalidSpaceRename(SyncFileItem::Down);
+ item->_instruction = CSYNC_INSTRUCTION_NEW;
+ item->_direction = SyncFileItem::Up;
+ item->_originalFile = item->_file;
+ item->_file = item->_renameTarget;
finalize();
return;
}
diff --git a/src/libsync/propagateremotemkdir.cpp b/src/libsync/propagateremotemkdir.cpp
index ac1b5b62a..f95fbca01 100644
--- a/src/libsync/propagateremotemkdir.cpp
+++ b/src/libsync/propagateremotemkdir.cpp
@@ -20,6 +20,7 @@
#include "deletejob.h"
#include "common/asserts.h"
#include "encryptfolderjob.h"
+#include "filesystem.h"
#include <QFile>
#include <QLoggingCategory>
@@ -169,6 +170,18 @@ void PropagateRemoteMkdir::finalizeMkColJob(QNetworkReply::NetworkError err, con
void PropagateRemoteMkdir::slotMkdir()
{
+ if (!_item->_originalFile.isEmpty() && !_item->_renameTarget.isEmpty() && _item->_renameTarget != _item->_originalFile) {
+ const auto existingFile = propagator()->fullLocalPath(propagator()->adjustRenamedPath(_item->_originalFile));
+ const auto targetFile = propagator()->fullLocalPath(_item->_renameTarget);
+ QString renameError;
+ if (!FileSystem::rename(existingFile, targetFile, &renameError)) {
+ done(SyncFileItem::NormalError, renameError);
+ return;
+ }
+ emit propagator()->touchedFile(existingFile);
+ emit propagator()->touchedFile(targetFile);
+ }
+
const auto path = _item->_file;
const auto slashPosition = path.lastIndexOf('/');
const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString();
diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp
index b899dc268..36aed9352 100644
--- a/src/libsync/propagateupload.cpp
+++ b/src/libsync/propagateupload.cpp
@@ -194,6 +194,18 @@ void PropagateUploadFileCommon::setDeleteExisting(bool enabled)
void PropagateUploadFileCommon::start()
{
+ if (!_item->_originalFile.isEmpty() && !_item->_renameTarget.isEmpty() && _item->_renameTarget != _item->_originalFile) {
+ const auto existingFile = propagator()->fullLocalPath(propagator()->adjustRenamedPath(_item->_originalFile));
+ const auto targetFile = propagator()->fullLocalPath(_item->_renameTarget);
+ QString renameError;
+ if (!FileSystem::rename(existingFile, targetFile, &renameError)) {
+ done(SyncFileItem::NormalError, renameError);
+ return;
+ }
+ emit propagator()->touchedFile(existingFile);
+ emit propagator()->touchedFile(targetFile);
+ }
+
const auto path = _item->_file;
const auto slashPosition = path.lastIndexOf('/');
const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString();
diff --git a/test/testlocaldiscovery.cpp b/test/testlocaldiscovery.cpp
index fa714129d..d84f95345 100644
--- a/test/testlocaldiscovery.cpp
+++ b/test/testlocaldiscovery.cpp
@@ -223,6 +223,7 @@ private slots:
fakeFolder.localModifier().insert(fileWithSpaces4);
fakeFolder.localModifier().insert(fileWithSpaces5);
fakeFolder.localModifier().insert(fileWithSpaces6);
+ fakeFolder.localModifier().mkdir(QStringLiteral(" with spaces "));
QVERIFY(fakeFolder.syncOnce());
@@ -244,6 +245,10 @@ private slots:
QVERIFY(fakeFolder.currentLocalState().find("A/bla"));
QVERIFY(!fakeFolder.currentLocalState().find(fileWithSpaces6));
+ QVERIFY(fakeFolder.currentLocalState().find(QStringLiteral("with spaces")));
+ QVERIFY(!fakeFolder.currentLocalState().find(QStringLiteral(" with spaces ")));
+
+ fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, {QStringLiteral("foo"), QStringLiteral("bar"), QStringLiteral("bla"), QStringLiteral("A/foo"), QStringLiteral("A/bar"), QStringLiteral("A/bla")});
QVERIFY(fakeFolder.syncOnce());
QVERIFY(fakeFolder.currentRemoteState().find(fileWithSpaces1.trimmed()));
@@ -275,6 +280,11 @@ private slots:
QVERIFY(!fakeFolder.currentRemoteState().find(fileWithSpaces6));
QVERIFY(fakeFolder.currentLocalState().find("A/bla"));
QVERIFY(!fakeFolder.currentLocalState().find(fileWithSpaces6));
+
+ QVERIFY(fakeFolder.currentRemoteState().find(QStringLiteral("with spaces")));
+ QVERIFY(!fakeFolder.currentRemoteState().find(QStringLiteral(" with spaces ")));
+ QVERIFY(fakeFolder.currentLocalState().find(QStringLiteral("with spaces")));
+ QVERIFY(!fakeFolder.currentLocalState().find(QStringLiteral(" with spaces ")));
}
void testCreateFileWithTrailingSpaces_localAndRemoteTrimmedDoNotExist_renameFile()