2012-02-15 12:30:37 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
#include "mirall/csyncthread.h"
|
|
|
|
#include "mirall/mirallconfigfile.h"
|
2012-09-27 19:22:08 +04:00
|
|
|
#include "mirall/theme.h"
|
2012-12-05 19:45:28 +04:00
|
|
|
#include "mirall/logger.h"
|
2013-01-21 16:29:17 +04:00
|
|
|
#include "mirall/owncloudinfo.h"
|
2013-05-03 21:11:00 +04:00
|
|
|
#include "owncloudpropagator.h"
|
2013-05-06 18:59:11 +04:00
|
|
|
#include "progressdatabase.h"
|
2012-05-21 18:48:49 +04:00
|
|
|
|
2012-12-06 19:24:53 +04:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-04 19:14:38 +04:00
|
|
|
#include <assert.h>
|
|
|
|
|
2012-02-15 12:30:37 +04:00
|
|
|
#include <QDebug>
|
2013-01-14 15:13:29 +04:00
|
|
|
#include <QSslSocket>
|
2012-02-15 12:30:37 +04:00
|
|
|
#include <QDir>
|
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTextStream>
|
2012-02-28 19:49:13 +04:00
|
|
|
#include <QTime>
|
2012-08-26 13:47:45 +04:00
|
|
|
#include <QApplication>
|
2012-12-11 15:49:48 +04:00
|
|
|
#include <QUrl>
|
2012-12-13 22:52:07 +04:00
|
|
|
#include <QSslCertificate>
|
2012-08-26 13:47:45 +04:00
|
|
|
|
2012-02-15 12:30:37 +04:00
|
|
|
namespace Mirall {
|
|
|
|
|
2012-03-13 20:37:43 +04:00
|
|
|
/* static variables to hold the credentials */
|
2012-08-02 12:17:15 +04:00
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
QMutex CSyncThread::_mutex;
|
2013-04-15 17:55:54 +04:00
|
|
|
QMutex CSyncThread::_syncMutex;
|
2012-03-21 21:03:49 +04:00
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
CSyncThread::CSyncThread(CSYNC *csync, const QString &localPath, const QString &remotePath)
|
2012-02-15 12:30:37 +04:00
|
|
|
{
|
2012-03-22 19:22:08 +04:00
|
|
|
_mutex.lock();
|
2013-05-03 21:11:00 +04:00
|
|
|
_localPath = localPath;
|
|
|
|
_remotePath = remotePath;
|
2013-04-20 14:15:27 +04:00
|
|
|
_csync_ctx = csync;
|
2012-03-22 19:22:08 +04:00
|
|
|
_mutex.unlock();
|
2012-02-15 12:30:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CSyncThread::~CSyncThread()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-05 13:41:31 +04:00
|
|
|
QString CSyncThread::csyncErrorToString( CSYNC_ERROR_CODE err ) const
|
2012-12-20 19:45:56 +04:00
|
|
|
{
|
|
|
|
QString errStr;
|
|
|
|
|
|
|
|
switch( err ) {
|
|
|
|
case CSYNC_ERR_NONE:
|
|
|
|
errStr = tr("Success.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_LOG:
|
|
|
|
errStr = tr("CSync Logging setup failed.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_LOCK:
|
|
|
|
errStr = tr("CSync failed to create a lock file.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_STATEDB_LOAD:
|
|
|
|
errStr = tr("CSync failed to load the state db.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_MODULE:
|
2013-02-21 15:21:42 +04:00
|
|
|
errStr = tr("<p>The %1 plugin for csync could not be loaded.<br/>Please verify the installation!</p>").arg(Theme::instance()->appNameGUI());
|
2012-12-20 19:45:56 +04:00
|
|
|
break;
|
|
|
|
case CSYNC_ERR_TIMESKEW:
|
|
|
|
errStr = tr("The system time on this client is different than the system time on the server. "
|
|
|
|
"Please use a time synchronization service (NTP) on the server and client machines "
|
|
|
|
"so that the times remain the same.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_FILESYSTEM:
|
|
|
|
errStr = tr("CSync could not detect the filesystem type.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_TREE:
|
|
|
|
errStr = tr("CSync got an error while processing internal trees.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_MEM:
|
|
|
|
errStr = tr("CSync failed to reserve memory.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_PARAM:
|
|
|
|
errStr = tr("CSync fatal parameter error.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_UPDATE:
|
|
|
|
errStr = tr("CSync processing step update failed.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_RECONCILE:
|
|
|
|
errStr = tr("CSync processing step reconcile failed.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_PROPAGATE:
|
|
|
|
errStr = tr("CSync processing step propagate failed.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_ACCESS_FAILED:
|
2013-04-20 14:15:27 +04:00
|
|
|
errStr = tr("<p>The target directory does not exist.</p><p>Please check the sync setup.</p>");
|
2012-12-20 19:45:56 +04:00
|
|
|
// this is critical. The database has to be removed.
|
2013-05-05 13:41:31 +04:00
|
|
|
// emit wipeDb(); FIXME - what about this?
|
2012-12-20 19:45:56 +04:00
|
|
|
break;
|
|
|
|
case CSYNC_ERR_REMOTE_CREATE:
|
|
|
|
case CSYNC_ERR_REMOTE_STAT:
|
|
|
|
errStr = tr("A remote file can not be written. Please check the remote access.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_LOCAL_CREATE:
|
|
|
|
case CSYNC_ERR_LOCAL_STAT:
|
|
|
|
errStr = tr("The local filesystem can not be written. Please check permissions.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_PROXY:
|
|
|
|
errStr = tr("CSync failed to connect through a proxy.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_LOOKUP:
|
|
|
|
errStr = tr("CSync failed to lookup proxy or server.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_AUTH_SERVER:
|
2013-02-21 15:21:42 +04:00
|
|
|
errStr = tr("CSync failed to authenticate at the %1 server.").arg(Theme::instance()->appNameGUI());
|
2012-12-20 19:45:56 +04:00
|
|
|
break;
|
|
|
|
case CSYNC_ERR_AUTH_PROXY:
|
|
|
|
errStr = tr("CSync failed to authenticate at the proxy.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_CONNECT:
|
|
|
|
errStr = tr("CSync failed to connect to the network.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_TIMEOUT:
|
|
|
|
errStr = tr("A network connection timeout happend.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_HTTP:
|
|
|
|
errStr = tr("A HTTP transmission error happened.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_PERM:
|
|
|
|
errStr = tr("CSync failed due to not handled permission deniend.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_NOT_FOUND:
|
|
|
|
errStr = tr("CSync failed to find a specific file.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_EXISTS:
|
|
|
|
errStr = tr("CSync tried to create a directory that already exists.");
|
|
|
|
break;
|
|
|
|
case CSYNC_ERR_NOSPC:
|
2013-02-21 15:21:42 +04:00
|
|
|
errStr = tr("CSync: No space on %1 server available.").arg(Theme::instance()->appNameGUI());
|
2012-12-20 19:45:56 +04:00
|
|
|
break;
|
|
|
|
case CSYNC_ERR_UNSPEC:
|
|
|
|
errStr = tr("CSync unspecified error.");
|
|
|
|
|
|
|
|
default:
|
|
|
|
errStr = tr("An internal error number %1 happend.").arg( (int) err );
|
|
|
|
}
|
|
|
|
|
|
|
|
return errStr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:41:52 +04:00
|
|
|
int CSyncThread::treewalkLocal( TREE_WALK_FILE* file, void *data )
|
|
|
|
{
|
|
|
|
return static_cast<CSyncThread*>(data)->treewalkFile( file, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSyncThread::treewalkRemote( TREE_WALK_FILE* file, void *data )
|
|
|
|
{
|
|
|
|
return static_cast<CSyncThread*>(data)->treewalkFile( file, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSyncThread::walkFinalize(TREE_WALK_FILE* file, void *data )
|
|
|
|
{
|
2013-05-04 17:32:11 +04:00
|
|
|
return static_cast<CSyncThread*>(data)->treewalkFinalize( file);
|
2013-01-15 23:41:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int CSyncThread::treewalkFile( TREE_WALK_FILE *file, bool remote )
|
|
|
|
{
|
|
|
|
if( ! file ) return -1;
|
|
|
|
SyncFileItem item;
|
|
|
|
item._file = QString::fromUtf8( file->path );
|
|
|
|
item._instruction = file->instruction;
|
|
|
|
item._dir = SyncFileItem::None;
|
2013-05-03 21:11:00 +04:00
|
|
|
item._isDirectory = file->type == CSYNC_FTW_TYPE_DIR;
|
|
|
|
item._modtime = file->modtime;
|
2013-05-06 18:59:11 +04:00
|
|
|
item._etag = file->md5;
|
2013-01-15 23:41:52 +04:00
|
|
|
|
|
|
|
SyncFileItem::Direction dir;
|
|
|
|
|
|
|
|
int re = 0;
|
|
|
|
|
2013-02-14 19:25:00 +04:00
|
|
|
switch(file->instruction) {
|
|
|
|
case CSYNC_INSTRUCTION_NONE:
|
|
|
|
case CSYNC_INSTRUCTION_IGNORE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!_needsUpdate)
|
|
|
|
_needsUpdate = true;
|
|
|
|
}
|
2013-01-15 23:41:52 +04:00
|
|
|
switch(file->instruction) {
|
|
|
|
case CSYNC_INSTRUCTION_NONE:
|
|
|
|
// No need to do anything.
|
|
|
|
return re;
|
|
|
|
break;
|
|
|
|
case CSYNC_INSTRUCTION_RENAME:
|
|
|
|
dir = !remote ? SyncFileItem::Down : SyncFileItem::Up;
|
|
|
|
item._renameTarget = QString::fromUtf8( file->rename_path );
|
|
|
|
break;
|
|
|
|
case CSYNC_INSTRUCTION_REMOVE:
|
|
|
|
dir = !remote ? SyncFileItem::Down : SyncFileItem::Up;
|
|
|
|
break;
|
|
|
|
case CSYNC_INSTRUCTION_CONFLICT:
|
|
|
|
case CSYNC_INSTRUCTION_IGNORE:
|
|
|
|
case CSYNC_INSTRUCTION_ERROR:
|
|
|
|
dir = SyncFileItem::None;
|
|
|
|
break;
|
|
|
|
case CSYNC_INSTRUCTION_EVAL:
|
|
|
|
case CSYNC_INSTRUCTION_NEW:
|
|
|
|
case CSYNC_INSTRUCTION_SYNC:
|
|
|
|
case CSYNC_INSTRUCTION_STAT_ERROR:
|
|
|
|
case CSYNC_INSTRUCTION_DELETED:
|
|
|
|
case CSYNC_INSTRUCTION_UPDATED:
|
|
|
|
default:
|
|
|
|
dir = remote ? SyncFileItem::Down : SyncFileItem::Up;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
item._dir = dir;
|
|
|
|
_syncedItems.append(item);
|
|
|
|
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
2013-05-04 17:32:11 +04:00
|
|
|
int CSyncThread::treewalkFinalize(TREE_WALK_FILE* file)
|
2013-01-15 23:41:52 +04:00
|
|
|
{
|
2013-05-04 17:32:11 +04:00
|
|
|
if (file->instruction == CSYNC_INSTRUCTION_IGNORE)
|
2013-05-03 21:11:00 +04:00
|
|
|
return 0;
|
|
|
|
|
2013-01-15 23:41:52 +04:00
|
|
|
SyncFileItem item;
|
|
|
|
item._file= QString::fromUtf8(file->path);
|
|
|
|
|
2013-05-04 17:32:11 +04:00
|
|
|
// Update the instruction and etag in the csync rb_tree so it is saved on the database
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
QHash<QString, Action>::const_iterator action = performedActions.constFind(item._file);
|
|
|
|
if (action != performedActions.constEnd()) {
|
2013-05-04 17:32:11 +04:00
|
|
|
if (file->instruction != CSYNC_INSTRUCTION_NONE) {
|
|
|
|
// it is NONE if we are in the wrong tree (remote vs. local)
|
|
|
|
file->instruction = action->instruction;
|
|
|
|
}
|
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
if (!action->etag.isNull()) {
|
2013-05-04 17:32:11 +04:00
|
|
|
// Update the etag even for INSTRUCTION_NONE (eg. renames)
|
2013-05-03 21:11:00 +04:00
|
|
|
file->md5 = action->etag.constData();
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 23:41:52 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-15 22:29:27 +04:00
|
|
|
struct CSyncRunScopeHelper {
|
2013-04-20 14:15:27 +04:00
|
|
|
CSyncRunScopeHelper(CSYNC *ctx, CSyncThread *parent)
|
|
|
|
: _ctx(ctx), _parent(parent)
|
2013-02-15 22:29:27 +04:00
|
|
|
{
|
2013-04-20 14:15:27 +04:00
|
|
|
_t.start();
|
2013-02-15 22:29:27 +04:00
|
|
|
}
|
|
|
|
~CSyncRunScopeHelper() {
|
2013-04-20 14:15:27 +04:00
|
|
|
csync_commit(_ctx);
|
2013-02-15 22:29:27 +04:00
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
qDebug() << "CSync run took " << _t.elapsed() << " Milliseconds";
|
|
|
|
emit(_parent->finished());
|
|
|
|
_parent->_syncMutex.unlock();
|
2013-02-15 22:29:27 +04:00
|
|
|
}
|
2013-04-20 14:15:27 +04:00
|
|
|
CSYNC *_ctx;
|
|
|
|
QTime _t;
|
|
|
|
CSyncThread *_parent;
|
2013-02-15 22:29:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void CSyncThread::handleSyncError(CSYNC *ctx, const char *state) {
|
|
|
|
CSYNC_ERROR_CODE err = csync_get_error( ctx );
|
|
|
|
const char *errMsg = csync_get_error_string( ctx );
|
2013-05-05 13:41:31 +04:00
|
|
|
QString errStr = csyncErrorToString(err);
|
|
|
|
if( errMsg ) {
|
|
|
|
errStr += QLatin1String("<br/>");
|
|
|
|
errStr += QString::fromUtf8(errMsg);
|
|
|
|
}
|
2013-02-15 22:29:27 +04:00
|
|
|
qDebug() << " #### ERROR during "<< state << ": " << errStr;
|
|
|
|
switch (err) {
|
|
|
|
case CSYNC_ERR_SERVICE_UNAVAILABLE:
|
|
|
|
case CSYNC_ERR_CONNECT:
|
|
|
|
emit csyncUnavailable();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
emit csyncError(errStr);
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2012-08-26 13:47:45 +04:00
|
|
|
void CSyncThread::startSync()
|
2012-02-15 12:30:37 +04:00
|
|
|
{
|
2013-04-15 17:55:54 +04:00
|
|
|
if (!_syncMutex.tryLock()) {
|
|
|
|
qDebug() << Q_FUNC_INFO << "WARNING: Another sync seems to be running. Not starting a new one.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
if( ! _csync_ctx ) {
|
|
|
|
qDebug() << "XXXXXXXXXXXXXXXX FAIL: do not have csync_ctx!";
|
|
|
|
}
|
2013-04-04 19:14:38 +04:00
|
|
|
qDebug() << Q_FUNC_INFO << "Sync started";
|
|
|
|
|
2012-08-26 13:47:45 +04:00
|
|
|
qDebug() << "starting to sync " << qApp->thread() << QThread::currentThread();
|
2013-05-07 19:47:29 +04:00
|
|
|
_syncedItems.clear();
|
2012-03-22 19:22:08 +04:00
|
|
|
|
2012-03-21 21:03:49 +04:00
|
|
|
_mutex.lock();
|
2013-02-14 19:25:00 +04:00
|
|
|
_needsUpdate = false;
|
2013-02-14 20:34:52 +04:00
|
|
|
_mutex.unlock();
|
2012-08-30 19:50:42 +04:00
|
|
|
|
2013-02-15 22:29:27 +04:00
|
|
|
// cleans up behind us and emits finished() to ease error handling
|
2013-04-20 14:15:27 +04:00
|
|
|
CSyncRunScopeHelper helper(_csync_ctx, this);
|
2012-12-11 15:49:48 +04:00
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
csync_set_userdata(_csync_ctx, this);
|
2012-02-15 12:30:37 +04:00
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
// csync_set_auth_callback( _csync_ctx, getauth );
|
|
|
|
csync_set_progress_callback( _csync_ctx, progress );
|
2012-12-05 15:29:35 +04:00
|
|
|
|
2012-08-09 16:13:20 +04:00
|
|
|
qDebug() << "#### Update start #################################################### >>";
|
2013-04-20 14:15:27 +04:00
|
|
|
if( csync_update(_csync_ctx) < 0 ) {
|
|
|
|
handleSyncError(_csync_ctx, "csync_update");
|
2013-02-15 22:29:27 +04:00
|
|
|
return;
|
2012-03-22 19:22:08 +04:00
|
|
|
}
|
2012-08-09 16:13:20 +04:00
|
|
|
qDebug() << "<<#### Update end ###########################################################";
|
2012-02-15 12:30:37 +04:00
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
if( csync_reconcile(_csync_ctx) < 0 ) {
|
|
|
|
handleSyncError(_csync_ctx, "cysnc_reconcile");
|
2013-02-15 22:29:27 +04:00
|
|
|
return;
|
2012-03-22 19:22:08 +04:00
|
|
|
}
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2013-02-20 20:26:07 +04:00
|
|
|
bool walkOk = true;
|
2013-04-20 14:15:27 +04:00
|
|
|
if( csync_walk_local_tree(_csync_ctx, &treewalkLocal, 0) < 0 ) {
|
2013-02-15 22:29:27 +04:00
|
|
|
qDebug() << "Error in local treewalk.";
|
2013-02-20 20:26:07 +04:00
|
|
|
walkOk = false;
|
2013-01-15 23:41:52 +04:00
|
|
|
}
|
2013-04-20 14:15:27 +04:00
|
|
|
if( walkOk && csync_walk_remote_tree(_csync_ctx, &treewalkRemote, 0) < 0 ) {
|
2013-02-15 22:29:27 +04:00
|
|
|
qDebug() << "Error in remote treewalk.";
|
2013-01-15 23:41:52 +04:00
|
|
|
}
|
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
qSort(_syncedItems);
|
|
|
|
|
2013-02-14 19:25:00 +04:00
|
|
|
if (_needsUpdate)
|
|
|
|
emit(started());
|
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
ne_session_s *session = 0;
|
|
|
|
// that call to set property actually is a get which will return the session
|
|
|
|
csync_set_module_property(_csync_ctx, "get_dav_session", &session);
|
|
|
|
Q_ASSERT(session);
|
|
|
|
|
2013-05-06 18:59:11 +04:00
|
|
|
ProgressDatabase db;
|
|
|
|
db.load(_localPath);
|
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
QString lastDeleted;
|
2013-05-06 18:59:11 +04:00
|
|
|
OwncloudPropagator propagator(session, _localPath, _remotePath, &db);
|
2013-05-07 19:47:29 +04:00
|
|
|
|
2013-05-08 15:30:30 +04:00
|
|
|
for (SyncFileItemVector::iterator it = _syncedItems.begin();
|
|
|
|
it != _syncedItems.end() && !propagator._hasFatalError; ++it) {
|
2013-05-07 19:47:29 +04:00
|
|
|
const SyncFileItem &item = *it;
|
2013-05-03 21:11:00 +04:00
|
|
|
Action a;
|
|
|
|
if (!lastDeleted.isEmpty() && item._file.startsWith(lastDeleted)
|
|
|
|
&& item._instruction == CSYNC_INSTRUCTION_REMOVE) {
|
2013-05-04 17:32:11 +04:00
|
|
|
// If the item's name starts with the name of the previously deleted directory, we
|
|
|
|
// can assume this file was already destroyed by the previous recursive call.
|
2013-05-03 21:11:00 +04:00
|
|
|
a.instruction = CSYNC_INSTRUCTION_DELETED;
|
|
|
|
performedActions.insert(item._file, a);
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-04 19:14:25 +04:00
|
|
|
propagator._etag.clear(); // FIXME : set to the right one
|
2013-05-03 21:11:00 +04:00
|
|
|
a.instruction = propagator.propagate(item);
|
2013-05-04 17:32:11 +04:00
|
|
|
|
2013-05-05 13:41:31 +04:00
|
|
|
// if the propagator had an error for a file, put the error string into the synced item
|
2013-05-07 19:47:29 +04:00
|
|
|
if( propagator._errorCode != CSYNC_ERR_NONE
|
|
|
|
|| a.instruction == CSYNC_INSTRUCTION_ERROR) {
|
|
|
|
it->_instruction = CSYNC_INSTRUCTION_ERROR;
|
|
|
|
it->_errorString = csyncErrorToString( propagator._errorCode );
|
|
|
|
it->_errorDetail = propagator._errorString;
|
|
|
|
it->_httpCode = propagator._httpStatusCode;
|
|
|
|
qDebug() << "File " << item._file << " propagator error " << item._errorString;
|
2013-05-05 13:41:31 +04:00
|
|
|
}
|
|
|
|
|
2013-05-04 17:32:11 +04:00
|
|
|
if (item._isDirectory && item._instruction == CSYNC_INSTRUCTION_REMOVE
|
2013-05-05 14:33:46 +04:00
|
|
|
&& a.instruction == CSYNC_INSTRUCTION_DELETED) {
|
2013-05-03 21:11:00 +04:00
|
|
|
lastDeleted = item._file;
|
|
|
|
} else {
|
|
|
|
lastDeleted.clear();
|
|
|
|
}
|
|
|
|
|
2013-05-04 19:14:25 +04:00
|
|
|
a.etag = propagator._etag;
|
2013-05-03 21:11:00 +04:00
|
|
|
performedActions.insert(item._file, a);
|
|
|
|
|
2013-05-05 14:33:46 +04:00
|
|
|
if (item._instruction == CSYNC_INSTRUCTION_RENAME
|
|
|
|
&& a.instruction == CSYNC_INSTRUCTION_DELETED) {
|
2013-05-04 17:32:11 +04:00
|
|
|
// we should update the etag on the destination as well
|
|
|
|
a.instruction = CSYNC_INSTRUCTION_NONE;
|
|
|
|
performedActions.insert(item._renameTarget, a);
|
|
|
|
}
|
|
|
|
|
2013-05-05 14:33:46 +04:00
|
|
|
if (!item._isDirectory && a.instruction == CSYNC_INSTRUCTION_UPDATED
|
|
|
|
&& item._dir == SyncFileItem::Down) {
|
|
|
|
emit fileReceived(item._file);
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO progress %;
|
2012-02-28 19:49:13 +04:00
|
|
|
}
|
2013-01-15 23:41:52 +04:00
|
|
|
|
2013-05-03 21:11:00 +04:00
|
|
|
// if( csync_propagate(_csync_ctx) < 0 ) {
|
|
|
|
// handleSyncError(_csync_ctx, "cysnc_reconcile");
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
2013-05-06 18:59:11 +04:00
|
|
|
db.save(_localPath);
|
|
|
|
|
2013-02-20 20:26:07 +04:00
|
|
|
if( walkOk ) {
|
2013-04-20 14:15:27 +04:00
|
|
|
if( csync_walk_local_tree(_csync_ctx, &walkFinalize, 0) < 0 ||
|
|
|
|
csync_walk_remote_tree( _csync_ctx, &walkFinalize, 0 ) < 0 ) {
|
2013-04-22 17:06:28 +04:00
|
|
|
qDebug() << "Error in finalize treewalk.";
|
2013-02-20 20:26:07 +04:00
|
|
|
} else {
|
2013-01-15 23:41:52 +04:00
|
|
|
// emit the treewalk results.
|
2013-02-20 20:26:07 +04:00
|
|
|
emit treeWalkResult(_syncedItems);
|
|
|
|
}
|
2013-01-15 23:41:52 +04:00
|
|
|
}
|
2013-04-04 19:14:38 +04:00
|
|
|
qDebug() << Q_FUNC_INFO << "Sync finished";
|
2012-02-28 19:49:13 +04:00
|
|
|
}
|
|
|
|
|
2013-05-05 14:33:46 +04:00
|
|
|
// TODO: remove: this is no longer used with the new propagator
|
2012-12-11 15:49:48 +04:00
|
|
|
void CSyncThread::progress(const char *remote_url, enum csync_notify_type_e kind,
|
|
|
|
long long o1, long long o2, void *userdata)
|
|
|
|
{
|
|
|
|
(void) o1; (void) o2;
|
|
|
|
if (kind == CSYNC_NOTIFY_FINISHED_DOWNLOAD) {
|
2012-12-12 23:06:59 +04:00
|
|
|
QString path = QUrl::fromEncoded(remote_url).toString();
|
2012-12-11 15:49:48 +04:00
|
|
|
CSyncThread *thread = static_cast<CSyncThread*>(userdata);
|
|
|
|
thread->fileReceived(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 12:30:37 +04:00
|
|
|
}
|