Skip to content

Commit

Permalink
Merge pull request #6143 from nextcloud/backport/6134/stable-3.10
Browse files Browse the repository at this point in the history
[stable-3.10] Bugfix/restore folders recursively
  • Loading branch information
mgallien authored Oct 17, 2023
2 parents a21e89d + 3392933 commit ead2907
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ void Application::setupLogging()
logger->setupTemporaryFolderLogDir();
}

#if defined QT_DEBUG
logger->setLogFlush(true);
logger->setLogDebug(true);
#endif

logger->enterNextLogFile();

qCInfo(lcApplication) << "##################" << _theme->appName()
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/clientsideencryption.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define OPENSSL_SUPPRESS_DEPRECATED

#include "clientsideencryption.h"

#include <openssl/rsa.h>
Expand Down
7 changes: 4 additions & 3 deletions src/libsync/owncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,9 @@ private slots:
/** Emit the finished signal and make sure it is only emitted once */
void emitFinished(OCC::SyncFileItem::Status status)
{
if (!_finishedEmited)
emit finished(status == SyncFileItem::Success);
if (!_finishedEmited) {
emit finished(status);
}
_abortRequested = false;
_finishedEmited = true;
}
Expand All @@ -645,7 +646,7 @@ private slots:
void newItem(const OCC::SyncFileItemPtr &);
void itemCompleted(const SyncFileItemPtr &item, OCC::ErrorCategory category);
void progress(const OCC::SyncFileItem &, qint64 bytes);
void finished(bool success);
void finished(OCC::SyncFileItem::Status status);

/** Emitted when propagation has problems with a locked file. */
void seenLockedFile(const QString &fileName);
Expand Down
9 changes: 5 additions & 4 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,13 +947,13 @@ void SyncEngine::slotItemCompleted(const SyncFileItemPtr &item, const ErrorCateg
emit itemCompleted(item, category);
}

void SyncEngine::slotPropagationFinished(bool success)
void SyncEngine::slotPropagationFinished(OCC::SyncFileItem::Status status)
{
if (_propagator->_anotherSyncNeeded && _anotherSyncNeeded == NoFollowUpSync) {
_anotherSyncNeeded = ImmediateFollowUp;
}

if (success && _discoveryPhase) {
if ((status == SyncFileItem::Success || status == SyncFileItem::BlacklistedError) && _discoveryPhase) {
_journal->setDataFingerprint(_discoveryPhase->_dataFingerprint);
}

Expand All @@ -970,7 +970,7 @@ void SyncEngine::slotPropagationFinished(bool success)
_progressInfo->_status = ProgressInfo::Done;
emit transmissionProgress(*_progressInfo);

finalize(success);
finalize(status == SyncFileItem::Success);
}

void SyncEngine::finalize(bool success)
Expand Down Expand Up @@ -1036,8 +1036,9 @@ void SyncEngine::restoreOldFiles(SyncFileItemVector &syncItems)
*/

for (const auto &syncItem : qAsConst(syncItems)) {
if (syncItem->_direction != SyncFileItem::Down)
if (syncItem->_direction != SyncFileItem::Down || syncItem->_isSelectiveSync) {
continue;
}

switch (syncItem->_instruction) {
case CSYNC_INSTRUCTION_SYNC:
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private slots:

void slotItemCompleted(const OCC::SyncFileItemPtr &item, const OCC::ErrorCategory category);
void slotDiscoveryFinished();
void slotPropagationFinished(bool success);
void slotPropagationFinished(SyncFileItem::Status status);
void slotProgress(const OCC::SyncFileItem &item, qint64 current);
void slotCleanPollsJobAborted(const QString &error, const OCC::ErrorCategory category);

Expand Down
38 changes: 37 additions & 1 deletion test/testselectivesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class TestSelectiveSync : public QObject
Q_OBJECT

private slots:

void initTestCase()
{
Logger::instance()->setLogFlush(true);
Logger::instance()->setLogDebug(true);
}

void testSelectiveSyncBigFolders()
{
Expand Down Expand Up @@ -86,6 +90,38 @@ private slots:
QCOMPARE(sizeRequests.count(), 0);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testRestoreSubFolderForDataFingerPrint()
{
const auto mkcolVerb = QByteArray{"MKCOL"};
FakeFolder fakeFolder{{}};
fakeFolder.localModifier().mkdir("topFolder");
fakeFolder.localModifier().mkdir("topFolder/subFolder");
fakeFolder.localModifier().insert("topFolder/subFolder/a");
fakeFolder.remoteModifier().extraDavProperties = "<oc:data-fingerprint>initial_finger_print</oc:data-fingerprint>";

QVERIFY(fakeFolder.syncOnce());

auto mkdirRequestsCounter = 0;
fakeFolder.setServerOverride([&mkdirRequestsCounter, mkcolVerb](QNetworkAccessManager::Operation, const QNetworkRequest &req, QIODevice *device)
-> QNetworkReply * {
Q_UNUSED(device)

if (req.attribute(QNetworkRequest::CustomVerbAttribute) == mkcolVerb) {
++mkdirRequestsCounter;
}
qDebug() << req.attribute(QNetworkRequest::CustomVerbAttribute);

return nullptr;
});

fakeFolder.syncEngine().journal()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
QStringList() << QLatin1String("topFolder"));
fakeFolder.remoteModifier().extraDavProperties = "<oc:data-fingerprint>changed_finger_print</oc:data-fingerprint>";

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(mkdirRequestsCounter, 0);
}
};

QTEST_GUILESS_MAIN(TestSelectiveSync)
Expand Down

0 comments on commit ead2907

Please sign in to comment.