mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 21:15:55 +03:00
Merge pull request #4399 from nextcloud/bugfix/doNotRemoveRenamedFileWithSpacesInName
avoid deleting renamed file with spaces in name
This commit is contained in:
commit
468a33cfa8
4 changed files with 39 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue