nextcloud-desktop/src/mirall/csyncthread.cpp

619 lines
20 KiB
C++
Raw Normal View History

/*
* 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"
#include "mirall/theme.h"
#include "mirall/logger.h"
#include "mirall/owncloudinfo.h"
#include "owncloudpropagator.h"
#include "progressdatabase.h"
#include "creds/abstractcredentials.h"
2012-05-21 18:48:49 +04:00
#ifdef Q_OS_WIN
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <assert.h>
#include <QDebug>
#include <QSslSocket>
#include <QDir>
#include <QMutexLocker>
#include <QThread>
#include <QStringList>
#include <QTextStream>
#include <QTime>
#include <QApplication>
#include <QUrl>
2012-12-13 22:52:07 +04:00
#include <QSslCertificate>
namespace Mirall {
/* static variables to hold the credentials */
QMutex CSyncThread::_mutex;
QMutex CSyncThread::_syncMutex;
CSyncThread::CSyncThread(CSYNC *csync, const QString &localPath, const QString &remotePath)
{
_mutex.lock();
_localPath = localPath;
_remotePath = remotePath;
_csync_ctx = csync;
_mutex.unlock();
2013-05-16 15:54:22 +04:00
qRegisterMetaType<SyncFileItem>("SyncFileItem");
2013-08-21 17:29:04 +04:00
qRegisterMetaType<CSYNC_STATUS>("CSYNC_STATUS");
}
CSyncThread::~CSyncThread()
{
}
//Convert an error code from csync to a user readable string.
// Keep that function thread safe as it can be called from the sync thread or the main thread
2013-08-21 17:29:04 +04:00
QString CSyncThread::csyncErrorToString(CSYNC_STATUS err)
2012-12-20 19:45:56 +04:00
{
QString errStr;
switch( err ) {
case CSYNC_STATUS_OK:
2012-12-20 19:45:56 +04:00
errStr = tr("Success.");
break;
case CSYNC_STATUS_NO_LOCK:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed to create a lock file.");
break;
case CSYNC_STATUS_STATEDB_LOAD_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed to load the state db.");
break;
case CSYNC_STATUS_STATEDB_WRITE_ERROR:
errStr = tr("CSync failed to write the state db.");
break;
case CSYNC_STATUS_NO_MODULE:
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_STATUS_TIMESKEW:
2012-12-20 19:45:56 +04:00
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_STATUS_FILESYSTEM_UNKNOWN:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync could not detect the filesystem type.");
break;
case CSYNC_STATUS_TREE_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync got an error while processing internal trees.");
break;
case CSYNC_STATUS_MEMORY_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed to reserve memory.");
break;
case CSYNC_STATUS_PARAM_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync fatal parameter error.");
break;
case CSYNC_STATUS_UPDATE_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync processing step update failed.");
break;
case CSYNC_STATUS_RECONCILE_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync processing step reconcile failed.");
break;
case CSYNC_STATUS_PROPAGATE_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync processing step propagate failed.");
break;
case CSYNC_STATUS_REMOTE_ACCESS_ERROR:
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
break;
case CSYNC_STATUS_REMOTE_CREATE_ERROR:
case CSYNC_STATUS_REMOTE_STAT_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("A remote file can not be written. Please check the remote access.");
break;
case CSYNC_STATUS_LOCAL_CREATE_ERROR:
case CSYNC_STATUS_LOCAL_STAT_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("The local filesystem can not be written. Please check permissions.");
break;
case CSYNC_STATUS_PROXY_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed to connect through a proxy.");
break;
case CSYNC_STATUS_PROXY_AUTH_ERROR:
errStr = tr("CSync could not authenticate at the proxy.");
break;
case CSYNC_STATUS_LOOKUP_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed to lookup proxy or server.");
break;
case CSYNC_STATUS_SERVER_AUTH_ERROR:
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_STATUS_CONNECT_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed to connect to the network.");
break;
case CSYNC_STATUS_TIMEOUT:
2012-12-20 19:45:56 +04:00
errStr = tr("A network connection timeout happend.");
break;
case CSYNC_STATUS_HTTP_ERROR:
2012-12-20 19:45:56 +04:00
errStr = tr("A HTTP transmission error happened.");
break;
case CSYNC_STATUS_PERMISSION_DENIED:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed due to not handled permission deniend.");
break;
case CSYNC_STATUS_NOT_FOUND:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync failed to find a specific file.");
break;
case CSYNC_STATUS_FILE_EXISTS:
2012-12-20 19:45:56 +04:00
errStr = tr("CSync tried to create a directory that already exists.");
break;
case CSYNC_STATUS_OUT_OF_SPACE:
errStr = tr("CSync: No space on %1 server available.").arg(Theme::instance()->appNameGUI());
2012-12-20 19:45:56 +04:00
break;
case CSYNC_STATUS_QUOTA_EXCEEDED:
errStr = tr("CSync: No space on %1 server available.").arg(Theme::instance()->appNameGUI());
2012-12-20 19:45:56 +04:00
break;
case CSYNC_STATUS_UNSUCCESSFUL:
2012-12-20 19:45:56 +04:00
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._originalFile = file->path;
2013-01-15 23:41:52 +04:00
item._instruction = file->instruction;
item._dir = SyncFileItem::None;
if(file->error_string) {
item._errorString = QString::fromUtf8(file->error_string);
}
item._isDirectory = file->type == CSYNC_FTW_TYPE_DIR;
item._modtime = file->modtime;
item._etag = file->md5;
// item._size = file->size;
2013-01-15 23:41:52 +04:00
SyncFileItem::Direction dir;
int re = 0;
if (file->instruction != CSYNC_INSTRUCTION_IGNORE
&& file->instruction != CSYNC_INSTRUCTION_REMOVE) {
_hasFiles = true;
}
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 );
if (item._isDirectory)
_renamedFolders.insert(item._file, item._renameTarget);
2013-01-15 23:41:52 +04:00
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;
}
switch( file->type ) {
case CSYNC_FTW_TYPE_DIR:
item._type = SyncFileItem::Directory;
break;
case CSYNC_FTW_TYPE_FILE:
item._type = SyncFileItem::File;
break;
case CSYNC_FTW_TYPE_SLINK:
item._type = SyncFileItem::SoftLink;
break;
default:
item._type = SyncFileItem::UnknownType;
}
2013-01-15 23:41:52 +04:00
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-01-15 23:41:52 +04:00
return 0;
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
QHash<QByteArray, Action>::const_iterator action = _performedActions.constFind(file->path);
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)
2013-01-15 23:41:52 +04:00
2013-08-14 21:59:16 +04:00
qDebug() << "UPDATING " << file->path << action->instruction;
2013-01-15 23:41:52 +04:00
2013-05-04 17:32:11 +04:00
file->instruction = action->instruction;
}
if (!action->etag.isNull()) {
2013-05-04 17:32:11 +04:00
// Update the etag even for INSTRUCTION_NONE (eg. renames)
file->md5 = action->etag.constData();
}
}
2013-01-15 23:41:52 +04:00
return 0;
}
void CSyncThread::handleSyncError(CSYNC *ctx, const char *state) {
2013-08-21 17:29:04 +04:00
CSYNC_STATUS err = CSYNC_STATUS(csync_get_status( ctx ));
const char *errMsg = csync_get_status_string( ctx );
2013-08-21 17:29:04 +04:00
QString errStr = csyncErrorToString(err);
if( errMsg ) {
errStr += QLatin1String("<br/>");
errStr += QString::fromUtf8(errMsg);
}
qDebug() << " #### ERROR during "<< state << ": " << errStr;
if( CSYNC_STATUS_IS_EQUAL( err, CSYNC_STATUS_SERVICE_UNAVAILABLE ) ||
CSYNC_STATUS_IS_EQUAL( err, CSYNC_STATUS_CONNECT_ERROR )) {
emit csyncUnavailable();
} else {
emit csyncError(errStr);
}
}
2013-01-15 23:41:52 +04:00
void CSyncThread::startSync()
{
if (!_syncMutex.tryLock()) {
qDebug() << Q_FUNC_INFO << "WARNING: Another sync seems to be running. Not starting a new one.";
return;
}
if( ! _csync_ctx ) {
qDebug() << "XXXXXXXXXXXXXXXX FAIL: do not have csync_ctx!";
}
qDebug() << Q_FUNC_INFO << "Sync started";
qDebug() << "starting to sync " << qApp->thread() << QThread::currentThread();
2013-05-07 19:47:29 +04:00
_syncedItems.clear();
_mutex.lock();
_needsUpdate = false;
_mutex.unlock();
// maybe move this somewhere else where it can influence a running sync?
MirallConfigFile cfg;
csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
csync_set_userdata(_csync_ctx, this);
// TODO: This should be a part of this method, but we don't have
// any way to get "session_key" module property from csync. Had we
// have it, then we could keep this code and remove it from
// AbstractCredentials implementations.
cfg.getCredentials()->syncContextPreStart(_csync_ctx);
// if (_lastAuthCookies.length() > 0) {
// // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply
// // when https://github.com/owncloud/core/pull/4042 is merged.
// QString cookiesAsString;
// foreach(QNetworkCookie c, _lastAuthCookies) {
// cookiesAsString += c.name();
// cookiesAsString += '=';
// cookiesAsString += c.value();
// cookiesAsString += "; ";
// }
// csync_set_module_property(_csync_ctx, "session_key", cookiesAsString.to
// }
// csync_set_auth_callback( _csync_ctx, getauth );
2013-05-16 15:54:22 +04:00
_syncTime.start();
QElapsedTimer updateTime;
updateTime.start();
qDebug() << "#### Update start #################################################### >>";
if( csync_update(_csync_ctx) < 0 ) {
handleSyncError(_csync_ctx, "csync_update");
return;
}
2013-05-16 15:54:22 +04:00
qDebug() << "<<#### Update end #################################################### " << updateTime.elapsed();
if( csync_reconcile(_csync_ctx) < 0 ) {
handleSyncError(_csync_ctx, "csync_reconcile");
return;
}
2013-01-15 23:41:52 +04:00
2013-08-14 21:59:16 +04:00
_progressInfo = Progress::Info();
_hasFiles = false;
bool walkOk = true;
if( csync_walk_local_tree(_csync_ctx, &treewalkLocal, 0) < 0 ) {
qDebug() << "Error in local treewalk.";
walkOk = false;
2013-01-15 23:41:52 +04:00
}
if( walkOk && csync_walk_remote_tree(_csync_ctx, &treewalkRemote, 0) < 0 ) {
qDebug() << "Error in remote treewalk.";
2013-01-15 23:41:52 +04:00
}
// Adjust the paths for the renames.
for (SyncFileItemVector::iterator it = _syncedItems.begin();
it != _syncedItems.end(); ++it) {
it->_file = adjustRenamedPath(it->_file);
}
qSort(_syncedItems);
if (!_hasFiles && !_syncedItems.isEmpty()) {
qDebug() << Q_FUNC_INFO << "All the files are going to be removed, asking the user";
bool cancel = false;
emit aboutToRemoveAllFiles(_syncedItems.first()._dir, &cancel);
if (cancel) {
qDebug() << Q_FUNC_INFO << "Abort sync";
return;
}
}
if (_needsUpdate)
emit(started());
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-16 15:54:22 +04:00
_progressDataBase.load(_localPath);
_propagator.reset(new OwncloudPropagator (session, _localPath, _remotePath, &_progressDataBase));
2013-08-21 17:29:04 +04:00
connect(_propagator.data(), SIGNAL(completed(SyncFileItem, CSYNC_STATUS)),
this, SLOT(transferCompleted(SyncFileItem, CSYNC_STATUS)), Qt::QueuedConnection);
2013-08-14 21:59:16 +04:00
connect(_propagator.data(), SIGNAL(progress(Progress::Kind,QString,quint64,quint64)),
this, SLOT(slotProgress(Progress::Kind,QString,quint64,quint64)));
2013-05-16 15:54:22 +04:00
_iterator = 0;
2013-08-14 21:59:16 +04:00
int downloadLimit = 0;
if (cfg.useDownloadLimit()) {
downloadLimit = cfg.downloadLimit() * 1000;
}
_propagator->_downloadLimit = downloadLimit;
int uploadLimit = -75; // 75%
int useUpLimit = cfg.useUploadLimit();
if ( useUpLimit >= 1) {
uploadLimit = cfg.uploadLimit() * 1000;
} else if (useUpLimit == 0) {
uploadLimit = 0;
}
2013-08-14 21:59:16 +04:00
_propagator->_uploadLimit = uploadLimit;
slotProgress(Progress::StartSync, QString(), 0, 0);
2013-01-15 23:41:52 +04:00
2013-08-14 21:59:16 +04:00
startNextTransfer();
2013-05-16 15:54:22 +04:00
}
2013-05-07 19:47:29 +04:00
2013-08-21 17:29:04 +04:00
void CSyncThread::transferCompleted(const SyncFileItem &item, CSYNC_STATUS error)
2013-05-16 15:54:22 +04:00
{
Action a;
a.instruction = item._instruction;
2013-05-16 15:54:22 +04:00
// if the propagator had an error for a file, put the error string into the synced item
2013-08-21 17:29:04 +04:00
if( error != CSYNC_STATUS_OK
2013-05-16 15:54:22 +04:00
|| a.instruction == CSYNC_INSTRUCTION_ERROR) {
// Search for the item in the starting from _iterator because it should be a bit before it.
// This works because SyncFileItem::operator== only compare the file name;
2013-05-16 15:54:22 +04:00
int idx = _syncedItems.lastIndexOf(item, _iterator);
if (idx >= 0) {
_syncedItems[idx]._instruction = CSYNC_INSTRUCTION_ERROR;
_syncedItems[idx]._errorString = csyncErrorToString( error );
2013-08-14 21:59:16 +04:00
_syncedItems[idx]._errorDetail = item._errorDetail;
_syncedItems[idx]._httpCode = item._httpCode;
2013-05-16 15:54:22 +04:00
qDebug() << "File " << item._file << " propagator error " << _syncedItems[idx]._errorString
<< "(" << item._errorString << ")";
}
2013-05-04 17:32:11 +04:00
if (item._isDirectory && item._instruction == CSYNC_INSTRUCTION_REMOVE
&& a.instruction == CSYNC_INSTRUCTION_DELETED) {
2013-05-16 15:54:22 +04:00
_lastDeleted = item._file;
} else {
2013-05-16 15:54:22 +04:00
_lastDeleted.clear();
}
2013-05-16 15:54:22 +04:00
}
a.etag = item._etag;
2013-05-16 15:54:22 +04:00
_performedActions.insert(item._originalFile, a);
2013-05-04 17:32:11 +04:00
2013-05-16 15:54:22 +04:00
if (item._instruction == CSYNC_INSTRUCTION_RENAME) {
if (a.instruction == CSYNC_INSTRUCTION_DELETED) {
// we should update the etag on the destination as well
a.instruction = CSYNC_INSTRUCTION_NONE;
} else { // ERROR
a.instruction = CSYNC_INSTRUCTION_ERROR;
}
2013-05-16 15:54:22 +04:00
_performedActions.insert(item._renameTarget.toUtf8(), a);
2013-01-15 23:41:52 +04:00
}
2013-08-14 21:59:16 +04:00
if (!item._isDirectory && a.instruction == CSYNC_INSTRUCTION_UPDATED) {
slotProgress((item._dir != SyncFileItem::Up) ? Progress::EndDownload : Progress::EndUpload,
item._file, item._size, item._size);
_progressInfo.current_file_no++;
_progressInfo.overall_current_bytes += item._size;
}
2013-01-15 23:41:52 +04:00
2013-05-16 15:54:22 +04:00
startNextTransfer();
}
2013-05-16 15:54:22 +04:00
void CSyncThread::startNextTransfer()
{
while (_iterator < _syncedItems.size() && !_propagator->_hasFatalError) {
const SyncFileItem &item = _syncedItems.at(_iterator);
++_iterator;
if (!_lastDeleted.isEmpty() && item._file.startsWith(_lastDeleted)
&& item._instruction == CSYNC_INSTRUCTION_REMOVE) {
// 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.
Action a;
a.instruction = CSYNC_INSTRUCTION_DELETED;
_performedActions.insert(item._originalFile, a);
continue;
}
2013-05-16 15:54:22 +04:00
_propagator->_etag.clear(); // FIXME : set to the right one
2013-08-14 21:59:16 +04:00
if (item._instruction == CSYNC_INSTRUCTION_SYNC || item._instruction == CSYNC_INSTRUCTION_NEW
|| item._instruction == CSYNC_INSTRUCTION_CONFLICT) {
slotProgress((item._dir != SyncFileItem::Up) ? Progress::StartDownload : Progress::StartUpload,
item._file, 0, item._size);
}
2013-05-16 15:54:22 +04:00
_propagator->propagate(item);
return; //propagate is async.
}
// Everything is finished.
_progressDataBase.save(_localPath);
if( csync_walk_local_tree(_csync_ctx, &walkFinalize, 0) < 0 ||
csync_walk_remote_tree( _csync_ctx, &walkFinalize, 0 ) < 0 ) {
qDebug() << "Error in finalize treewalk.";
} else {
// emit the treewalk results.
emit treeWalkResult(_syncedItems);
2013-01-15 23:41:52 +04:00
}
2013-05-16 15:54:22 +04:00
csync_commit(_csync_ctx);
qDebug() << "CSync run took " << _syncTime.elapsed() << " Milliseconds";
2013-08-14 21:59:16 +04:00
slotProgress(Progress::EndSync,QString(), 0 , 0);
2013-05-16 15:54:22 +04:00
emit finished();
_propagator.reset(0);
_syncMutex.unlock();
}
Progress::Kind CSyncThread::csyncToProgressKind( enum csync_notify_type_e kind )
{
Progress::Kind pKind = Progress::Invalid;
switch(kind) {
case CSYNC_NOTIFY_INVALID:
pKind = Progress::Invalid;
break;
case CSYNC_NOTIFY_START_SYNC_SEQUENCE:
pKind = Progress::StartSync;
break;
case CSYNC_NOTIFY_START_DOWNLOAD:
pKind = Progress::StartDownload;
break;
case CSYNC_NOTIFY_START_UPLOAD:
pKind = Progress::StartUpload;
break;
case CSYNC_NOTIFY_PROGRESS:
pKind = Progress::Context;
break;
case CSYNC_NOTIFY_FINISHED_DOWNLOAD:
pKind = Progress::EndDownload;
break;
case CSYNC_NOTIFY_FINISHED_UPLOAD:
pKind = Progress::EndUpload;
break;
case CSYNC_NOTIFY_FINISHED_SYNC_SEQUENCE:
pKind = Progress::EndSync;
break;
2013-08-03 23:33:19 +04:00
case CSYNC_NOTIFY_START_DELETE:
pKind = Progress::StartDelete;
break;
case CSYNC_NOTIFY_END_DELETE:
pKind = Progress::EndDelete;
break;
case CSYNC_NOTIFY_ERROR:
pKind = Progress::Error;
break;
default:
pKind = Progress::Invalid;
break;
}
return pKind;
}
2013-08-14 21:59:16 +04:00
void CSyncThread::slotProgress(Progress::Kind kind, const QString &file, quint64 curr, quint64 total)
{
2013-08-14 21:59:16 +04:00
Progress::Info pInfo = _progressInfo;
pInfo.kind = kind;
pInfo.current_file = file;
pInfo.file_size = total;
pInfo.current_file_bytes = curr;
pInfo.overall_current_bytes += curr;
pInfo.timestamp = QDateTime::currentDateTime();
// Connect to something in folder!
2013-08-14 21:59:16 +04:00
transmissionProgress( pInfo );
}
/* Given a path on the remote, give the path as it is when the rename is done */
QString CSyncThread::adjustRenamedPath(const QString& original)
{
int slashPos = original.size();
while ((slashPos = original.lastIndexOf('/' , slashPos - 1)) > 0) {
QHash< QString, QString >::const_iterator it = _renamedFolders.constFind(original.left(slashPos));
if (it != _renamedFolders.constEnd()) {
return *it + original.mid(slashPos);
}
}
return original;
}
} // ns Mirall