Use another way to detect that the server was reconfigured

Before, we would only detect it if all the files were removed, and no
file where added or changed. This may not be enough because there might
be a welcome.txt file. Now, we check that none of the file stays the same,
and some files are removed.

Relates issue #1948
This commit is contained in:
Olivier Goffart 2014-07-15 11:22:16 +02:00
parent 51e9c5fd96
commit d697969f36
3 changed files with 17 additions and 16 deletions

View file

@ -704,10 +704,7 @@ void Folder::slotTransmissionProgress(const Progress::Info &pi)
void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction, bool *cancel)
{
#ifndef TOKEN_AUTH_ONLY
QString msg = direction == SyncFileItem::Down ?
tr("This sync would remove all the files in the local sync folder '%1'.\n"
"If you or your administrator have reset your account on the server, choose "
"\"Keep files\". If you want your data to be removed, choose \"Remove all files\".") :
QString msg =
tr("This sync would remove all the files in the sync folder '%1'.\n"
"This might be because the folder was silently reconfigured, or that all "
"the file were manually removed.\n"

View file

@ -61,7 +61,8 @@ SyncEngine::SyncEngine(CSYNC *ctx, const QString& localPath, const QString& remo
, _remoteUrl(remoteURL)
, _remotePath(remotePath)
, _journal(journal)
, _hasFiles(false)
, _hasNoneFiles(false)
, _hasRemoveFile(false)
, _downloadLimit(0)
, _uploadLimit(0)
@ -330,7 +331,7 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
dir = SyncFileItem::None;
} else {
// No need to do anything.
_hasFiles = true;
_hasNoneFiles = true;
emit syncItemDiscovered(item);
return re;
@ -343,6 +344,7 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
_renamedFolders.insert(item._file, item._renameTarget);
break;
case CSYNC_INSTRUCTION_REMOVE:
_hasRemoveFile = true;
dir = !remote ? SyncFileItem::Down : SyncFileItem::Up;
break;
case CSYNC_INSTRUCTION_CONFLICT:
@ -356,6 +358,11 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
case CSYNC_INSTRUCTION_STAT_ERROR:
default:
dir = remote ? SyncFileItem::Down : SyncFileItem::Up;
if (!remote && file->instruction == CSYNC_INSTRUCTION_SYNC) {
// An upload of an existing file means that the file was left unchanged on the server
// This count as a NONE for detecting if all the file on the server were changed
_hasNoneFiles = true;
}
break;
}
@ -364,11 +371,6 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
// if the item is on blacklist, the instruction was set to IGNORE
checkBlacklisting( &item );
if (file->instruction != CSYNC_INSTRUCTION_IGNORE
&& file->instruction != CSYNC_INSTRUCTION_REMOVE) {
_hasFiles = true;
}
if (!item._isDirectory) {
_progressInfo._totalFileCount++;
if (Progress::isSizeDependent(file->instruction)) {
@ -526,7 +528,8 @@ void SyncEngine::slotUpdateFinished(int updateResult)
_progressInfo = Progress::Info();
_hasFiles = false;
_hasNoneFiles = false;
_hasRemoveFile = false;
bool walkOk = true;
_seenFiles.clear();
@ -556,8 +559,8 @@ void SyncEngine::slotUpdateFinished(int updateResult)
emit aboutToPropagate(_syncedItems);
emit transmissionProgress(_progressInfo);
if (!_hasFiles && !_syncedItems.isEmpty()) {
qDebug() << Q_FUNC_INFO << "All the files are going to be removed, asking the user";
if (!_hasNoneFiles && _hasRemoveFile) {
qDebug() << Q_FUNC_INFO << "All the files are going to be changed, asking the user";
bool cancel = false;
emit aboutToRemoveAllFiles(_syncedItems.first()._direction, &cancel);
if (cancel) {

View file

@ -127,7 +127,8 @@ private:
QHash<QString, QString> _renamedFolders;
QString adjustRenamedPath(const QString &original);
bool _hasFiles; // true if there is at least one file that is not ignored or removed
bool _hasNoneFiles; // true if there is at least one file with instruction NONE
bool _hasRemoveFile; // true if there is at leasr one file with instruction REMOVE
int _downloadLimit;
int _uploadLimit;