Skip to content

Commit

Permalink
Refactor the overlay icon logic to show errors as a warning for paren…
Browse files Browse the repository at this point in the history
…t folders #3634

This also remove all smartness from the SocketApi about the status
of a file and solely use info from the current and last sync.
This simplifies the logic a lot and prevents any discrepancy between
the status shown in the activity log and the one displayed on the
overlay icon of a file.

The main benefit of the additional simplicity is that we are able
to push all new status of a file reliably (including warnings for
parent folders) to properly update the icon on overlay implementations
that don't allow us invalidating the status cache, like on OS X.

Both errors and warning from the last sync are now kept in a set,
which is used to also affect parent folders of an error.

To make sure that errors don't become warning icons on a second
sync, SyncFileItem::_hasBlacklistEntry is also interpreted as an error.
This also renames StatusIgnore to StatusWarning to match this semantic.

SyncEngine::aboutToPropagate is used in favor of SyncEngine::syncItemDiscovered
since the latter is emitted before file permission warnings are set on the
SyncFileItem. SyncEngine::finished is not used since we have all the
needed information in SyncEngine::itemCompleted.
  • Loading branch information
jturcotte committed Mar 28, 2016
1 parent 69aa39f commit 82190ea
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 235 deletions.
29 changes: 5 additions & 24 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,33 +1306,14 @@ void SyncEngine::restoreOldFiles()
}
}

bool SyncEngine::estimateState(QString fn, csync_ftw_type_e t, SyncFileStatus* s)
SyncFileItem* SyncEngine::findSyncItem(const QString &fileName) const
{
Q_UNUSED(t);
QString pat(fn);
if( t == CSYNC_FTW_TYPE_DIR && ! fn.endsWith(QLatin1Char('/'))) {
pat.append(QLatin1Char('/'));
}

Q_FOREACH(const SyncFileItemPtr &item, _syncedItems) {
//qDebug() << Q_FUNC_INFO << fn << item->_status << item->_file << fn.startsWith(item->_file) << item->_file.startsWith(fn);

if (item->_file.startsWith(pat) ||
item->_file == fn || item->_renameTarget == fn /* the same directory or file */) {
if (item->_status == SyncFileItem::NormalError
|| item->_status == SyncFileItem::FatalError)
s->set(SyncFileStatus::StatusError);
else if (item->_status == SyncFileItem::FileIgnored)
s->set(SyncFileStatus::StatusIgnore);
else if (item->_status == SyncFileItem::Success)
s->set(SyncFileStatus::StatusUpToDate);
else
s->set(SyncFileStatus::StatusSync);
qDebug() << Q_FUNC_INFO << "Setting" << fn << "to" << s->toSocketAPIString();
return true;
}
// Directories will appear in this list as well, and will get their status set once all children have been propagated
if ((item->_file == fileName || item->_renameTarget == fileName))
return item.data();
}
return false;
return 0;
}

qint64 SyncEngine::timeSinceFileTouched(const QString& fn) const
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
/* Return true if we detected that another sync is needed to complete the sync */
bool isAnotherSyncNeeded() { return _anotherSyncNeeded; }

bool estimateState(QString fn, csync_ftw_type_e t, SyncFileStatus* s);
SyncFileItem* findSyncItem(const QString &fileName) const;

/** Get the ms since a file was touched, or -1 if it wasn't.
*
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/syncfilestatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ QString SyncFileStatus::toSocketAPIString() const
case StatusSync:
statusString = QLatin1String("SYNC");
break;
case StatusIgnore:
case StatusWarning:
// The protocol says IGNORE, but all implementations show a yellow warning sign.
statusString = QLatin1String("IGNORE");
break;
case StatusUpToDate:
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncfilestatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OWNCLOUDSYNC_EXPORT SyncFileStatus
enum SyncFileStatusTag {
StatusNone,
StatusSync,
StatusIgnore,
StatusWarning,
StatusUpToDate,
StatusError,
};
Expand Down
Loading

0 comments on commit 82190ea

Please sign in to comment.