Skip to content

Commit

Permalink
Ignore upload error items and schedule a new sync in case there are r…
Browse files Browse the repository at this point in the history
…emoved items that need to be downsynced.

Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Sep 4, 2023
1 parent bfd5965 commit 5470aa9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ void DiscoveryPhase::enqueueDirectoryToDelete(const QString &path, ProcessDirect
void DiscoveryPhase::startJob(ProcessDirectoryJob *job)
{
ENFORCE(!_currentRootJob);
connect(this, &DiscoveryPhase::itemDiscovered, this, &DiscoveryPhase::slotItemDiscovered, Qt::UniqueConnection);
connect(job, &ProcessDirectoryJob::finished, this, [this, job] {
ENFORCE(_currentRootJob == sender());
_currentRootJob = nullptr;
Expand Down Expand Up @@ -267,6 +268,16 @@ void DiscoveryPhase::scheduleMoreJobs()
}
}

void DiscoveryPhase::slotItemDiscovered(const OCC::SyncFileItemPtr &item)
{
if (item->_instruction == CSYNC_INSTRUCTION_ERROR && item->_direction == SyncFileItem::Up) {
_hasUploadErrorItems = true;
}
if (item->_instruction == CSYNC_INSTRUCTION_REMOVE && item->_direction == SyncFileItem::Down) {
_hasDownloadRemovedItems = true;
}
}

DiscoverySingleLocalDirectoryJob::DiscoverySingleLocalDirectoryJob(const AccountPtr &account, const QString &localPath, OCC::Vfs *vfs, QObject *parent)
: QObject(parent), QRunnable(), _localPath(localPath), _account(account), _vfs(vfs)
{
Expand Down
6 changes: 6 additions & 0 deletions src/libsync/discoveryphase.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ class DiscoveryPhase : public QObject

QStringList _listExclusiveFiles;

bool _hasUploadErrorItems = false;
bool _hasDownloadRemovedItems = false;

signals:
void fatalError(const QString &errorString, const OCC::ErrorCategory errorCategory);
void itemDiscovered(const OCC::SyncFileItemPtr &item);
Expand All @@ -334,6 +337,9 @@ class DiscoveryPhase : public QObject
void silentlyExcluded(const QString &folderPath);

void addErrorToGui(const SyncFileItem::Status status, const QString &errorMessage, const QString &subject, const OCC::ErrorCategory category);

private slots:
void slotItemDiscovered(const OCC::SyncFileItemPtr &item);
};

/// Implementation of DiscoveryPhase::adjustRenamedPath
Expand Down
12 changes: 6 additions & 6 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,12 @@ void OwncloudPropagator::start(SyncFileItemVector &&items)
} while (index > 0);
}
}
items.erase(std::remove_if(items.begin(), items.end(), [&names](auto i) {
return !names.contains(QStringRef { &i->_file });
}),
items.end());
items.erase(std::remove_if(items.begin(),
items.end(),
[&names](auto i) {
return !names.contains(QStringRef{&i->_file});
}),
items.end());
}

QStringList files;
Expand Down Expand Up @@ -1330,7 +1332,6 @@ void PropagateDirectory::slotFirstJobFinished(SyncFileItem::Status status)
_firstJob.take()->deleteLater();

if (status != SyncFileItem::Success
&& status != SyncFileItem::NormalError
&& status != SyncFileItem::Restoration
&& status != SyncFileItem::Conflict) {
if (_state != Finished) {
Expand Down Expand Up @@ -1485,7 +1486,6 @@ void PropagateRootDirectory::slotSubJobsFinished(SyncFileItem::Status status)
}

if (status != SyncFileItem::Success
&& status != SyncFileItem::NormalError
&& status != SyncFileItem::Restoration
&& status != SyncFileItem::BlacklistedError
&& status != SyncFileItem::FileNameClash
Expand Down
9 changes: 9 additions & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,15 @@ void SyncEngine::slotDiscoveryFinished()
slotUnscheduleFilesDelayedSync();
}

if (_discoveryPhase->_hasDownloadRemovedItems && _discoveryPhase->_hasUploadErrorItems) {
for (const auto &item : _syncItems) {
if (item->_instruction == CSYNC_INSTRUCTION_ERROR && item->_direction == SyncFileItem::Up) {
item->_instruction = CSYNC_INSTRUCTION_IGNORE;
}
}
_anotherSyncNeeded = ImmediateFollowUp;
}

Q_ASSERT(std::is_sorted(_syncItems.begin(), _syncItems.end()));

qCInfo(lcEngine) << "#### Reconcile (aboutToPropagate) #################################################### " << _stopWatch.addLapTime(QStringLiteral("Reconcile (aboutToPropagate)")) << "ms";
Expand Down

0 comments on commit 5470aa9

Please sign in to comment.