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

[stable-3.13] Allow deletion of virtual suffix placeholder files #6856

Merged
merged 4 commits into from
Jun 28, 2024
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
8 changes: 0 additions & 8 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,14 +1082,6 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
qCWarning(lcDisco) << "Failed to delete a file record from the local DB" << path._original;
}
return;
} else if (dbEntry._type == ItemTypeVirtualFile && isVfsWithSuffix()) {
// If the virtual file is removed, recreate it.
// This is a precaution since the suffix files don't look like the real ones
// and we don't want users to accidentally delete server data because they
// might not expect that deleting the placeholder will have a remote effect.
item->_instruction = CSYNC_INSTRUCTION_NEW;
item->_direction = SyncFileItem::Down;
item->_type = ItemTypeVirtualFile;
} else if (!serverModified) {
// Removed locally: also remove on the server.
if (!dbEntry._serverHasIgnoredFiles) {
Expand Down
15 changes: 11 additions & 4 deletions src/libsync/propagateremotedelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ void PropagateRemoteDelete::start()

void PropagateRemoteDelete::createDeleteJob(const QString &filename)
{
qCInfo(lcPropagateRemoteDelete) << "Deleting file, local" << _item->_file << "remote" << filename;
Q_ASSERT(propagator());
auto remoteFilename = filename;
if (_item->_type == ItemType::ItemTypeVirtualFile) {
if (const auto vfs = propagator()->syncOptions()._vfs; vfs->mode() == Vfs::Mode::WithSuffix) {
// These are compile-time constants so no need to recreate each time
static constexpr auto suffixSize = std::string_view(APPLICATION_DOTVIRTUALFILE_SUFFIX).size();
remoteFilename.chop(suffixSize);
}
}

_job = new DeleteJob(propagator()->account(),
propagator()->fullRemotePath(filename),
this);
qCInfo(lcPropagateRemoteDelete) << "Deleting file, local" << _item->_file << "remote" << remoteFilename;

_job = new DeleteJob(propagator()->account(), propagator()->fullRemotePath(remoteFilename), this);
connect(_job.data(), &DeleteJob::finishedSignal, this, &PropagateRemoteDelete::slotDeleteJobFinished);
propagator()->_activeJobList.append(this);
_job->start();
Expand Down
14 changes: 12 additions & 2 deletions test/testsyncvirtualfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
*/

#include <QtTest>

Check failure on line 8 in test/testsyncvirtualfiles.cpp

View workflow job for this annotation

GitHub Actions / build

test/testsyncvirtualfiles.cpp:8:10 [clang-diagnostic-error]

'QtTest' file not found
#include "syncenginetestutils.h"
#include "common/vfs.h"
#include "config.h"
Expand Down Expand Up @@ -167,17 +167,27 @@
QCOMPARE(dbRecord(fakeFolder, "A/a1" DVSUFFIX)._fileSize, 65);
cleanup();

// If the local virtual file file is removed, it'll just be recreated
// If the local virtual file is removed, it should be gone remotely too
if (!doLocalDiscovery)
fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, { "A" });
fakeFolder.localModifier().remove("A/a1" DVSUFFIX);
QVERIFY(fakeFolder.syncOnce());
QVERIFY(!fakeFolder.currentLocalState().find("A/a1"));
QVERIFY(!fakeFolder.currentLocalState().find("A/a1" DVSUFFIX));
QVERIFY(!fakeFolder.remoteModifier().find("A/a1"));
cleanup();

// Restore the state prior to next test
// Essentially repeating creation of virtual file
fakeFolder.remoteModifier().insert("A/a1", 64);
fakeFolder.remoteModifier().setModTime("A/a1", someDate);
QVERIFY(fakeFolder.syncOnce());
QVERIFY(!fakeFolder.currentLocalState().find("A/a1"));
QVERIFY(fakeFolder.currentLocalState().find("A/a1" DVSUFFIX));
QCOMPARE(QFileInfo(fakeFolder.localPath() + "A/a1" DVSUFFIX).lastModified(), someDate);
QVERIFY(fakeFolder.currentRemoteState().find("A/a1"));
QVERIFY(itemInstruction(completeSpy, "A/a1" DVSUFFIX, CSYNC_INSTRUCTION_NEW));
QCOMPARE(dbRecord(fakeFolder, "A/a1" DVSUFFIX)._type, ItemTypeVirtualFile);
QCOMPARE(dbRecord(fakeFolder, "A/a1" DVSUFFIX)._fileSize, 65);
cleanup();

// Remote rename is propagated
Expand Down
Loading