mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Better protection against remote folder delete.
This commit is contained in:
parent
07ecd8527d
commit
928ef731c9
4 changed files with 35 additions and 10 deletions
|
@ -196,6 +196,9 @@ void CSyncThread::run()
|
|||
break;
|
||||
case CSYNC_ERR_ACCESS_FAILED:
|
||||
errStr = tr("<p>The target directory %1 does not exist.</p><p>Please check the sync setup.</p>").arg(_target);
|
||||
// this is critical. The database has to be removed.
|
||||
emitStateDb(csync); // to make the name of the csync db known.
|
||||
emit wipeDb();
|
||||
break;
|
||||
case CSYNC_ERR_MODULE:
|
||||
errStr = tr("<p>The ownCloud plugin for csync could not be loaded.<br/>Please verify the installation!</p>");
|
||||
|
@ -221,16 +224,7 @@ void CSyncThread::run()
|
|||
qDebug() << "WRN: Failed to set remote push atomar.";
|
||||
}
|
||||
|
||||
// After csync_init the statedb file name can be emitted
|
||||
statedb = csync_get_statedb_file( csync );
|
||||
if( statedb ) {
|
||||
QString stateDbFile = QString::fromUtf8(statedb);
|
||||
free((void*)statedb);
|
||||
|
||||
emit csyncStateDbFile( stateDbFile );
|
||||
} else {
|
||||
qDebug() << "WRN: Unable to get csync statedb file name";
|
||||
}
|
||||
emitStateDb(csync);
|
||||
|
||||
qDebug() << "############################################################### >>";
|
||||
if( csync_update(csync) < 0 ) {
|
||||
|
@ -291,6 +285,19 @@ cleanup:
|
|||
qDebug() << "CSync run took " << t.elapsed() << " Milliseconds";
|
||||
}
|
||||
|
||||
void CSyncThread::emitStateDb( CSYNC *csync )
|
||||
{
|
||||
// After csync_init the statedb file name can be emitted
|
||||
const char *statedb = csync_get_statedb_file( csync );
|
||||
if( statedb ) {
|
||||
QString stateDbFile = QString::fromUtf8(statedb);
|
||||
free((void*)statedb);
|
||||
|
||||
emit csyncStateDbFile( stateDbFile );
|
||||
} else {
|
||||
qDebug() << "WRN: Unable to get csync statedb file name";
|
||||
}
|
||||
}
|
||||
|
||||
void CSyncThread::setUserPwd( const QString& user, const QString& passwd )
|
||||
{
|
||||
|
|
|
@ -71,8 +71,11 @@ signals:
|
|||
void csyncError( const QString& );
|
||||
|
||||
void csyncStateDbFile( const QString& );
|
||||
void wipeDb();
|
||||
|
||||
private:
|
||||
void emitStateDb( CSYNC *csync );
|
||||
|
||||
static int getauth(const char *prompt,
|
||||
char *buf,
|
||||
size_t len,
|
||||
|
|
|
@ -41,6 +41,7 @@ ownCloudFolder::ownCloudFolder(const QString &alias,
|
|||
, _csync(0)
|
||||
, _pollTimerCnt(0)
|
||||
, _csyncError(false)
|
||||
, _wipeDb(false)
|
||||
, _lastSeenFiles(0)
|
||||
{
|
||||
#ifdef USE_INOTIFY
|
||||
|
@ -112,6 +113,7 @@ void ownCloudFolder::startSync(const QStringList &pathList)
|
|||
delete _csync;
|
||||
_errors.clear();
|
||||
_csyncError = false;
|
||||
_wipeDb = false;
|
||||
|
||||
MirallConfigFile cfgFile;
|
||||
|
||||
|
@ -148,6 +150,7 @@ void ownCloudFolder::startSync(const QStringList &pathList)
|
|||
QObject::connect(_csync, SIGNAL(terminated()), SLOT(slotCSyncTerminated()));
|
||||
connect(_csync, SIGNAL(csyncError(const QString)), SLOT(slotCSyncError(const QString)));
|
||||
connect(_csync, SIGNAL(csyncStateDbFile(QString)), SLOT(slotCsyncStateDbFile(QString)));
|
||||
connect(_csync, SIGNAL(wipeDb()),SLOT(slotWipeDb()));
|
||||
|
||||
connect( _csync, SIGNAL(treeWalkResult(WalkStats*)),
|
||||
this, SLOT(slotThreadTreeWalkResult(WalkStats*)));
|
||||
|
@ -232,6 +235,7 @@ void ownCloudFolder::slotCSyncFinished()
|
|||
qDebug() << " ** error Strings: " << _errors;
|
||||
_syncResult.setErrorStrings( _errors );
|
||||
qDebug() << " * owncloud csync thread finished with error";
|
||||
if( _wipeDb ) wipe();
|
||||
} else {
|
||||
_syncResult.setStatus(SyncResult::Success);
|
||||
}
|
||||
|
@ -263,6 +267,14 @@ void ownCloudFolder::slotTerminateSync()
|
|||
}
|
||||
}
|
||||
|
||||
// an error condition in csyncthread requires to get rid of the database to avoid deletion
|
||||
// of files.
|
||||
void ownCloudFolder::slotWipeDb()
|
||||
{
|
||||
qDebug() << "Wiping of the csync database is required!";
|
||||
_wipeDb = true;
|
||||
}
|
||||
|
||||
// This removes the csync File database if the sync folder definition is removed
|
||||
// permanentely. This is needed to provide a clean startup again in case another
|
||||
// local folder is synced to the same ownCloud.
|
||||
|
@ -286,6 +298,7 @@ void ownCloudFolder::wipe()
|
|||
if( ctmpFile.exists() ) {
|
||||
ctmpFile.remove();
|
||||
}
|
||||
_wipeDb = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ private slots:
|
|||
void slotThreadTreeWalkResult( WalkStats* );
|
||||
void slotCSyncTerminated();
|
||||
void slotCsyncStateDbFile(const QString&);
|
||||
void slotWipeDb();
|
||||
|
||||
#ifndef USE_INOTIFY
|
||||
void slotPollTimerRemoteCheck();
|
||||
|
@ -64,6 +65,7 @@ private:
|
|||
int _pollTimerExceed;
|
||||
QStringList _errors;
|
||||
bool _csyncError;
|
||||
bool _wipeDb;
|
||||
ulong _lastSeenFiles;
|
||||
QString _csyncStateDbFile;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue