Skip to content

Commit

Permalink
Refactoring and code-cleaning.
Browse files Browse the repository at this point in the history
Signed-off-by: allexzander <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Jun 14, 2021
1 parent b595b54 commit f205d77
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/gui/tray/ActivityData.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Activity
QString _file;
QUrl _link;
QDateTime _dateTime;
qint64 _expireAt = -1;
qint64 _expireAtMsecs = -1;
QString _accName;
QString _icon;
QString _iconData;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/tray/UserModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void User::slotProgressInfo(const QString &folder, const ProgressInfo &progress)
const auto &engine = f->syncEngine();
const auto style = engine.lastLocalDiscoveryStyle();
foreach (Activity activity, _activityModel->errorsList()) {
if (activity._expireAt > 0 && QDateTime::currentDateTime().toMSecsSinceEpoch() < activity._expireAt) {
if (activity._expireAtMsecs > 0 && QDateTime::currentDateTime().toMSecsSinceEpoch() < activity._expireAtMsecs) {
continue;
}
if (activity._folder != folder) {
Expand Down Expand Up @@ -436,7 +436,7 @@ void User::slotAddErrorToGui(const QString &folderAlias, SyncFileItem::Status st
activity._status = status;
const auto currentDateTime = QDateTime::currentDateTime();
activity._dateTime = QDateTime::fromString(currentDateTime.toString(), Qt::ISODate);
activity._expireAt = currentDateTime.addSecs(60 * 1).toMSecsSinceEpoch();
activity._expireAtMsecs = currentDateTime.addSecs(60 * 1).toMSecsSinceEpoch();
activity._subject = errorMessage;
activity._message = errorMessage;
activity._link = folderInstance->shortGuiLocalPath();
Expand Down
41 changes: 26 additions & 15 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,27 +894,38 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
_childModified = true;

auto postProcessLocalNew = [item, localEntry, path, this]() {
if (localEntry.isVirtualFile || localEntry.isDirectory) {
const bool isPlaceHolder = _discoveryData->_syncOptions._vfs->isDehydratedPlaceholder(_discoveryData->_localDir + path._local);

const bool isNonHydratedVfsFolder = (localEntry.isDirectory
&& _discoveryData->_syncOptions._vfs->mode() != Vfs::Off
&& *_discoveryData->_syncOptions._vfs->availability(path._local) == VfsItemAvailability::OnlineOnly);

// must be file placeholder or an online-only folder
if (isPlaceHolder || isNonHydratedVfsFolder) {
// TODO: We may want to execute the same logic for non-VFS mode, as, moving/renaming the same folder by 2 or more clients at the same time is not possible in Web UI.
// Keeping it like this (for VFS files and folders only) just to fix a user issue.
const auto isVfsEnabled = _discoveryData->_syncOptions._vfs && _discoveryData->_syncOptions._vfs->mode() != Vfs::Off;
if (localEntry.isVirtualFile || (localEntry.isDirectory && isVfsEnabled)) {
// must be a dehydrated placeholder
const bool isFilePlaceHolder = !localEntry.isDirectory && _discoveryData->_syncOptions._vfs->isDehydratedPlaceholder(_discoveryData->_localDir + path._local);

// a folder must be online-only (no files should be hydrated)
const bool isFolderPlaceholder = localEntry.isDirectory && *_discoveryData->_syncOptions._vfs->availability(path._local) == VfsItemAvailability::OnlineOnly;

Q_ASSERT(item->_instruction == CSYNC_INSTRUCTION_NEW);
if (item->_instruction == CSYNC_INSTRUCTION_NEW) {
qCWarning(lcDisco) << "Wiping virtual file without db entry for" << path._local;
}

// must be a file placeholder or an online-only folder placeholder
if (isFilePlaceHolder || isFolderPlaceholder) {
if (isFolderPlaceholder) {
qCInfo(lcDisco) << "Wiping virtual folder without db entry for" << path._local;
} else {
qCInfo(lcDisco) << "Wiping virtual file without db entry for" << path._local;
}
item->_instruction = CSYNC_INSTRUCTION_REMOVE;
item->_direction = SyncFileItem::Down;
// this flag needs to be unset, otherwise a folder would get marked as new in the processSubJobs
_childModified = false;
if (localEntry.isDirectory) {
if (_discoveryData) {
emit _discoveryData->addErrorToGui(SyncFileItem::SoftError, tr("Conflict when uploading a folder %1. It's going to get wiped!").arg(path._local));
}
if (isFolderPlaceholder && _discoveryData) {
emit _discoveryData->addErrorToGui(SyncFileItem::SoftError, tr("Conflict when uploading a folder %1. It's going to get wiped!").arg(path._local));
}
} else {
if (localEntry.isDirectory && !isNonHydratedVfsFolder) {
qCWarning(lcDisco) << "Virtual directory without db entry for" << path._local << "but it is half-hydrated, so, keeping it.";
if (localEntry.isDirectory && !isFolderPlaceholder) {
qCInfo(lcDisco) << "Virtual directory without db entry for" << path._local << "but it contains hydrated file(s), so let's keep it and reupload.";
if (_discoveryData) {
emit _discoveryData->addErrorToGui(SyncFileItem::SoftError, tr("Conflict when uploading some files to a folder %1. Those, conflicted, are going to get wiped!").arg(path._local));
}
Expand Down
2 changes: 0 additions & 2 deletions src/libsync/discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,5 @@ class ProcessDirectoryJob : public QObject
void finished();
// The root etag of this directory was fetched
void etag(const QString &, const QDateTime &time);

void addErrorToGui(SyncFileItem::Status status, const QString &errorMessage);
};
}
6 changes: 6 additions & 0 deletions src/libsync/progressdispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ class OWNCLOUDSYNC_EXPORT ProgressDispatcher : public QObject
*/
void syncError(const QString &folder, const QString &message, ErrorCategory category);

/**
* @brief Emitted when an error needs to be added into GUI
* @param[out] folder The folder which is being processed
* @param[out] status of the error
* @param[out] full error message
*/
void addErrorToGui(const QString &folder, SyncFileItem::Status status, const QString &errorMessage);

/**
Expand Down
7 changes: 1 addition & 6 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void SyncEngine::startSync()
_discoveryPhase.data(), PinState::AlwaysLocal, _journal->keyValueStoreGetInt("last_sync", 0), _discoveryPhase.data());
_discoveryPhase->startJob(discoveryJob);
connect(discoveryJob, &ProcessDirectoryJob::etag, this, &SyncEngine::slotRootEtagReceived);
connect(_discoveryPhase.data(), &DiscoveryPhase::addErrorToGui, this, &SyncEngine::slotAddErrorToGui);
connect(_discoveryPhase.data(), &DiscoveryPhase::addErrorToGui, this, &SyncEngine::addErrorToGui);
}

void SyncEngine::slotFolderDiscovered(bool local, const QString &folder)
Expand Down Expand Up @@ -1110,9 +1110,4 @@ void SyncEngine::slotInsufficientRemoteStorage()
emit syncError(msg, ErrorCategory::InsufficientRemoteStorage);
}

void SyncEngine::slotAddErrorToGui(SyncFileItem::Status status, const QString &errorMessage)
{
emit addErrorToGui(status, errorMessage);
}

} // namespace OCC
2 changes: 0 additions & 2 deletions src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ private slots:
void slotInsufficientLocalStorage();
void slotInsufficientRemoteStorage();

void slotAddErrorToGui(SyncFileItem::Status status, const QString &errorMessage);

private:
bool checkErrorBlacklisting(SyncFileItem &item);

Expand Down

0 comments on commit f205d77

Please sign in to comment.