2012-02-15 17:44:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.org>
|
|
|
|
*
|
|
|
|
* 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/owncloudfolder.h"
|
|
|
|
#include "mirall/mirallconfigfile.h"
|
2012-10-02 15:24:10 +04:00
|
|
|
#include "mirall/owncloudinfo.h"
|
2012-11-13 14:15:25 +04:00
|
|
|
#include "mirall/credentialstore.h"
|
2012-12-11 15:49:48 +04:00
|
|
|
#include "mirall/logger.h"
|
2013-04-20 14:15:27 +04:00
|
|
|
#include "mirall/utility.h"
|
2012-05-21 18:48:49 +04:00
|
|
|
|
|
|
|
#include <csync.h>
|
|
|
|
|
2012-02-15 17:44:09 +04:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTextStream>
|
2012-02-28 19:49:13 +04:00
|
|
|
#include <QTimer>
|
2012-08-02 12:17:15 +04:00
|
|
|
#include <QNetworkProxy>
|
2012-10-08 13:08:37 +04:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkProxyFactory>
|
2012-02-15 17:44:09 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
void csyncLogCatcher(CSYNC *ctx,
|
|
|
|
int verbosity,
|
|
|
|
const char *function,
|
|
|
|
const char *buffer,
|
|
|
|
void *userdata)
|
|
|
|
{
|
|
|
|
Logger::instance()->csyncLog( QString::fromUtf8(buffer) );
|
|
|
|
}
|
2012-03-30 15:57:02 +04:00
|
|
|
|
2012-12-12 22:30:28 +04:00
|
|
|
static QString replaceScheme(const QString &urlStr)
|
|
|
|
{
|
|
|
|
|
|
|
|
QUrl url( urlStr );
|
|
|
|
if( url.scheme() == QLatin1String("http") ) {
|
|
|
|
url.setScheme( QLatin1String("owncloud") );
|
|
|
|
} else {
|
|
|
|
// connect SSL!
|
|
|
|
url.setScheme( QLatin1String("ownclouds") );
|
|
|
|
}
|
|
|
|
return url.toString();
|
|
|
|
}
|
|
|
|
|
2012-02-15 17:44:09 +04:00
|
|
|
ownCloudFolder::ownCloudFolder(const QString &alias,
|
2013-04-20 14:15:27 +04:00
|
|
|
const QString &mpath,
|
2012-02-15 17:44:09 +04:00
|
|
|
const QString &secondPath,
|
|
|
|
QObject *parent)
|
2013-04-20 14:15:27 +04:00
|
|
|
: Folder(alias, mpath, secondPath, parent)
|
2012-08-26 13:47:45 +04:00
|
|
|
, _thread(0)
|
2012-02-15 17:44:09 +04:00
|
|
|
, _csync(0)
|
2012-03-22 19:22:08 +04:00
|
|
|
, _csyncError(false)
|
2013-01-16 17:39:43 +04:00
|
|
|
, _csyncUnavail(false)
|
2012-06-25 16:18:13 +04:00
|
|
|
, _wipeDb(false)
|
2012-02-15 17:44:09 +04:00
|
|
|
{
|
2013-02-14 19:19:48 +04:00
|
|
|
ServerActionNotifier *notifier = new ServerActionNotifier(this);
|
|
|
|
connect(notifier, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
|
|
|
|
connect(this, SIGNAL(syncFinished(SyncResult)), notifier, SLOT(slotSyncFinished(SyncResult)));
|
2012-02-29 18:25:16 +04:00
|
|
|
qDebug() << "****** ownCloud folder using watcher *******";
|
2012-03-08 14:39:31 +04:00
|
|
|
// The folder interval is set in the folder parent class.
|
2013-04-20 14:15:27 +04:00
|
|
|
|
2013-04-25 18:06:31 +04:00
|
|
|
QString url = replaceScheme(secondPath);
|
2013-04-20 14:15:27 +04:00
|
|
|
QString localpath = path();
|
|
|
|
|
|
|
|
if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url.toUtf8().data() ) < 0 ) {
|
|
|
|
qDebug() << "Unable to create csync-context!";
|
|
|
|
_csync_ctx = 0;
|
|
|
|
} else {
|
|
|
|
csync_set_log_callback( _csync_ctx, csyncLogCatcher );
|
|
|
|
csync_set_log_verbosity(_csync_ctx, 11);
|
|
|
|
|
|
|
|
MirallConfigFile cfgFile;
|
|
|
|
csync_set_config_dir( _csync_ctx, cfgFile.configPath().toUtf8() );
|
|
|
|
|
|
|
|
csync_enable_conflictcopys(_csync_ctx);
|
|
|
|
QString excludeList = cfgFile.excludeFile();
|
|
|
|
if( !excludeList.isEmpty() ) {
|
|
|
|
qDebug() << "==== added CSync exclude List: " << excludeList.toUtf8();
|
|
|
|
csync_add_exclude_list( _csync_ctx, excludeList.toUtf8() );
|
|
|
|
}
|
|
|
|
csync_set_auth_callback( _csync_ctx, getauth );
|
|
|
|
|
|
|
|
if( csync_init( _csync_ctx ) < 0 ) {
|
|
|
|
qDebug() << "Could not initialize csync!";
|
|
|
|
_csync_ctx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( _csync_ctx ) {
|
|
|
|
/* Store proxy */
|
|
|
|
QList<QNetworkProxy> proxies = QNetworkProxyFactory::proxyForQuery(QUrl(cfgFile.ownCloudUrl()));
|
|
|
|
// We set at least one in Application
|
|
|
|
Q_ASSERT(proxies.count() > 0);
|
|
|
|
QNetworkProxy proxy = proxies.first();
|
|
|
|
int proxyPort = proxy.port();
|
|
|
|
|
|
|
|
csync_set_module_property(_csync_ctx, "proxy_type", (char*) proxyTypeToCStr(proxy.type()) );
|
|
|
|
csync_set_module_property(_csync_ctx, "proxy_host", proxy.hostName().toUtf8().data() );
|
|
|
|
csync_set_module_property(_csync_ctx, "proxy_port", &proxyPort );
|
|
|
|
csync_set_module_property(_csync_ctx, "proxy_user", proxy.user().toUtf8().data() );
|
|
|
|
csync_set_module_property(_csync_ctx, "proxy_pwd" , proxy.password().toUtf8().data() );
|
|
|
|
|
|
|
|
csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
|
|
|
|
}
|
|
|
|
}
|
2012-02-15 17:44:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ownCloudFolder::~ownCloudFolder()
|
|
|
|
{
|
2013-05-16 15:26:05 +04:00
|
|
|
if( _thread ) {
|
|
|
|
_thread->quit();
|
|
|
|
csync_request_abort(_csync_ctx);
|
|
|
|
_thread->wait();
|
|
|
|
}
|
2013-04-20 14:15:27 +04:00
|
|
|
// Destroy csync here.
|
|
|
|
csync_destroy(_csync_ctx);
|
|
|
|
}
|
2012-06-11 12:10:07 +04:00
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
const char* ownCloudFolder::proxyTypeToCStr(QNetworkProxy::ProxyType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case QNetworkProxy::NoProxy:
|
|
|
|
return "NoProxy";
|
|
|
|
case QNetworkProxy::DefaultProxy:
|
|
|
|
return "DefaultProxy";
|
|
|
|
case QNetworkProxy::Socks5Proxy:
|
|
|
|
return "Socks5Proxy";
|
|
|
|
case QNetworkProxy::HttpProxy:
|
|
|
|
return "HttpProxy";
|
|
|
|
case QNetworkProxy::HttpCachingProxy:
|
|
|
|
return "HttpCachingProxy";
|
|
|
|
case QNetworkProxy::FtpCachingProxy:
|
|
|
|
return "FtpCachingProxy";
|
|
|
|
default:
|
|
|
|
return "NoProxy";
|
|
|
|
}
|
2012-02-15 17:44:09 +04:00
|
|
|
}
|
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
int ownCloudFolder::getauth(const char *prompt,
|
|
|
|
char *buf,
|
|
|
|
size_t len,
|
|
|
|
int echo,
|
|
|
|
int verify,
|
|
|
|
void *userdata
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int re = 0;
|
|
|
|
QMutex mutex;
|
|
|
|
|
|
|
|
QString qPrompt = QString::fromLatin1( prompt ).trimmed();
|
|
|
|
QString user = CredentialStore::instance()->user();
|
|
|
|
QString pwd = CredentialStore::instance()->password();
|
|
|
|
|
|
|
|
if( qPrompt == QLatin1String("Enter your username:") ) {
|
|
|
|
// qDebug() << "OOO Username requested!";
|
|
|
|
QMutexLocker locker( &mutex );
|
|
|
|
qstrncpy( buf, user.toUtf8().constData(), len );
|
|
|
|
} else if( qPrompt == QLatin1String("Enter your password:") ) {
|
|
|
|
QMutexLocker locker( &mutex );
|
|
|
|
// qDebug() << "OOO Password requested!";
|
|
|
|
qstrncpy( buf, pwd.toUtf8().constData(), len );
|
|
|
|
} else {
|
|
|
|
if( qPrompt.startsWith( QLatin1String("There are problems with the SSL certificate:"))) {
|
|
|
|
// SSL is requested. If the program came here, the SSL check was done by mirall
|
|
|
|
// It needs to be checked if the chain is still equal to the one which
|
|
|
|
// was verified by the user.
|
|
|
|
QRegExp regexp("fingerprint: ([\\w\\d:]+)");
|
|
|
|
bool certOk = false;
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
// This is the set of certificates which QNAM accepted, so we should accept
|
|
|
|
// them as well
|
|
|
|
QList<QSslCertificate> certs = ownCloudInfo::instance()->certificateChain();
|
|
|
|
|
|
|
|
while (!certOk && (pos = regexp.indexIn(qPrompt, 1+pos)) != -1) {
|
|
|
|
QString neon_fingerprint = regexp.cap(1);
|
|
|
|
|
|
|
|
foreach( const QSslCertificate& c, certs ) {
|
|
|
|
QString verified_shasum = Utility::formatFingerprint(c.digest(QCryptographicHash::Sha1).toHex());
|
|
|
|
qDebug() << "SSL Fingerprint from neon: " << neon_fingerprint << " compared to verified: " << verified_shasum;
|
|
|
|
if( verified_shasum == neon_fingerprint ) {
|
|
|
|
certOk = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// certOk = false; DEBUG setting, keep disabled!
|
|
|
|
if( !certOk ) { // Problem!
|
|
|
|
qstrcpy( buf, "no" );
|
|
|
|
re = -1;
|
|
|
|
} else {
|
|
|
|
qstrcpy( buf, "yes" ); // Certificate is fine!
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qDebug() << "Unknown prompt: <" << prompt << ">";
|
|
|
|
re = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-15 17:44:09 +04:00
|
|
|
bool ownCloudFolder::isBusy() const
|
|
|
|
{
|
2012-08-26 13:47:45 +04:00
|
|
|
return ( _thread && _thread->isRunning() );
|
2012-02-15 17:44:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ownCloudFolder::secondPath() const
|
|
|
|
{
|
2013-04-25 18:06:31 +04:00
|
|
|
QString re(Folder::secondPath());
|
2012-03-26 15:20:15 +04:00
|
|
|
MirallConfigFile cfg;
|
2013-04-25 18:06:31 +04:00
|
|
|
QString ocUrl = cfg.ownCloudUrl(QString::null, true);
|
|
|
|
if (ocUrl.endsWith(QLatin1Char('/')))
|
|
|
|
ocUrl.chop(1);
|
|
|
|
|
2012-04-30 10:56:56 +04:00
|
|
|
// qDebug() << "**** " << ocUrl << " <-> " << re;
|
2012-03-26 15:20:15 +04:00
|
|
|
if( re.startsWith( ocUrl ) ) {
|
|
|
|
re.remove( ocUrl );
|
|
|
|
}
|
|
|
|
|
|
|
|
return re;
|
2012-02-15 17:44:09 +04:00
|
|
|
}
|
|
|
|
|
2012-02-28 19:49:13 +04:00
|
|
|
void ownCloudFolder::startSync()
|
|
|
|
{
|
|
|
|
startSync( QStringList() );
|
|
|
|
}
|
|
|
|
|
2012-02-15 17:44:09 +04:00
|
|
|
void ownCloudFolder::startSync(const QStringList &pathList)
|
|
|
|
{
|
2012-08-26 13:47:45 +04:00
|
|
|
if (_thread && _thread->isRunning()) {
|
2012-02-15 17:44:09 +04:00
|
|
|
qCritical() << "* ERROR csync is still running and new sync requested.";
|
|
|
|
return;
|
|
|
|
}
|
2013-05-09 23:55:28 +04:00
|
|
|
if (_thread)
|
|
|
|
_thread->quit();
|
2012-08-26 13:47:45 +04:00
|
|
|
delete _csync;
|
|
|
|
delete _thread;
|
2012-03-22 19:22:08 +04:00
|
|
|
_errors.clear();
|
|
|
|
_csyncError = false;
|
2013-01-16 17:39:43 +04:00
|
|
|
_csyncUnavail = false;
|
2012-06-25 16:18:13 +04:00
|
|
|
_wipeDb = false;
|
2012-02-15 17:44:09 +04:00
|
|
|
|
2012-03-13 20:37:43 +04:00
|
|
|
MirallConfigFile cfgFile;
|
|
|
|
|
2012-06-20 14:52:21 +04:00
|
|
|
_syncResult.clearErrors();
|
2013-02-14 19:25:00 +04:00
|
|
|
_syncResult.setStatus( SyncResult::SyncPrepare );
|
|
|
|
emit syncStateChange();
|
2012-02-15 17:44:09 +04:00
|
|
|
|
2012-04-17 15:16:48 +04:00
|
|
|
|
2013-04-20 14:15:27 +04:00
|
|
|
qDebug() << "*** Start syncing";
|
2012-08-26 13:47:45 +04:00
|
|
|
_thread = new QThread(this);
|
2013-04-20 14:15:27 +04:00
|
|
|
_csync = new CSyncThread( _csync_ctx );
|
2012-08-26 13:47:45 +04:00
|
|
|
_csync->moveToThread(_thread);
|
2012-08-02 12:17:15 +04:00
|
|
|
|
2013-01-15 23:41:52 +04:00
|
|
|
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
|
|
|
|
connect( _csync, SIGNAL(treeWalkResult(const SyncFileItemVector&)),
|
|
|
|
this, SLOT(slotThreadTreeWalkResult(const SyncFileItemVector&)), Qt::QueuedConnection);
|
2012-08-02 12:17:15 +04:00
|
|
|
|
2012-08-26 13:47:45 +04:00
|
|
|
connect(_csync, SIGNAL(started()), SLOT(slotCSyncStarted()), Qt::QueuedConnection);
|
|
|
|
connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished()), Qt::QueuedConnection);
|
2012-12-11 15:49:48 +04:00
|
|
|
connect(_csync, SIGNAL(csyncError(QString)), SLOT(slotCSyncError(QString)), Qt::QueuedConnection);
|
2013-01-16 17:39:43 +04:00
|
|
|
connect(_csync, SIGNAL(csyncUnavailable()), SLOT(slotCsyncUnavailable()), Qt::QueuedConnection);
|
2012-08-26 13:47:45 +04:00
|
|
|
_thread->start();
|
|
|
|
QMetaObject::invokeMethod(_csync, "startSync", Qt::QueuedConnection);
|
2013-02-14 19:25:00 +04:00
|
|
|
emit syncStarted();
|
2012-02-15 17:44:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ownCloudFolder::slotCSyncStarted()
|
|
|
|
{
|
|
|
|
qDebug() << " * csync thread started";
|
2013-02-14 19:25:00 +04:00
|
|
|
_syncResult.setStatus(SyncResult::SyncRunning);
|
|
|
|
emit syncStateChange();
|
2012-02-15 17:44:09 +04:00
|
|
|
}
|
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
void ownCloudFolder::slotCSyncError(const QString& err)
|
|
|
|
{
|
|
|
|
_errors.append( err );
|
|
|
|
_csyncError = true;
|
|
|
|
}
|
|
|
|
|
2013-01-16 17:39:43 +04:00
|
|
|
void ownCloudFolder::slotCsyncUnavailable()
|
|
|
|
{
|
|
|
|
_csyncUnavail = true;
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:03:49 +04:00
|
|
|
void ownCloudFolder::slotCSyncFinished()
|
|
|
|
{
|
2012-04-30 10:56:56 +04:00
|
|
|
qDebug() << "-> CSync Finished slot with error " << _csyncError;
|
|
|
|
|
2012-03-22 19:22:08 +04:00
|
|
|
if (_csyncError) {
|
2012-04-17 15:16:48 +04:00
|
|
|
_syncResult.setStatus(SyncResult::Error);
|
2012-03-22 19:22:08 +04:00
|
|
|
|
|
|
|
qDebug() << " ** error Strings: " << _errors;
|
2012-04-17 15:16:48 +04:00
|
|
|
_syncResult.setErrorStrings( _errors );
|
2012-03-21 21:03:49 +04:00
|
|
|
qDebug() << " * owncloud csync thread finished with error";
|
2012-06-25 16:18:13 +04:00
|
|
|
if( _wipeDb ) wipe();
|
2013-01-16 17:39:43 +04:00
|
|
|
} else if (_csyncUnavail) {
|
|
|
|
_syncResult.setStatus(SyncResult::Unavailable);
|
2012-03-22 19:22:08 +04:00
|
|
|
} else {
|
2012-04-17 15:16:48 +04:00
|
|
|
_syncResult.setStatus(SyncResult::Success);
|
2012-03-22 19:22:08 +04:00
|
|
|
}
|
2012-03-21 21:03:49 +04:00
|
|
|
|
2012-08-26 13:47:45 +04:00
|
|
|
if( _thread && _thread->isRunning() ) {
|
|
|
|
_thread->quit();
|
|
|
|
}
|
2012-04-17 15:16:48 +04:00
|
|
|
emit syncFinished( _syncResult );
|
2012-02-15 17:44:09 +04:00
|
|
|
}
|
|
|
|
|
2013-01-15 23:41:52 +04:00
|
|
|
void ownCloudFolder::slotThreadTreeWalkResult(const SyncFileItemVector& items)
|
|
|
|
{
|
|
|
|
_syncResult.setSyncFileItemVector(items);
|
|
|
|
}
|
|
|
|
|
2012-04-30 10:56:56 +04:00
|
|
|
void ownCloudFolder::slotTerminateSync()
|
|
|
|
{
|
|
|
|
qDebug() << "folder " << alias() << " Terminating!";
|
2013-04-22 17:06:28 +04:00
|
|
|
MirallConfigFile cfg;
|
|
|
|
QString configDir = cfg.configPath();
|
2012-04-30 10:56:56 +04:00
|
|
|
qDebug() << "csync's Config Dir: " << configDir;
|
|
|
|
|
2013-05-09 23:55:28 +04:00
|
|
|
if( _thread && _csync ) {
|
|
|
|
csync_request_abort(_csync_ctx);
|
2013-05-16 19:35:40 +04:00
|
|
|
_thread->quit();
|
2012-08-26 13:47:45 +04:00
|
|
|
_thread->wait();
|
2013-02-14 19:28:06 +04:00
|
|
|
_csync->deleteLater();
|
2012-08-26 13:47:45 +04:00
|
|
|
delete _thread;
|
2012-04-30 10:56:56 +04:00
|
|
|
_csync = 0;
|
2012-08-26 13:47:45 +04:00
|
|
|
_thread = 0;
|
2013-05-09 23:55:28 +04:00
|
|
|
csync_resume(_csync_ctx);
|
2012-04-30 10:56:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ! configDir.isEmpty() ) {
|
|
|
|
QFile file( configDir + QLatin1String("/lock"));
|
|
|
|
if( file.exists() ) {
|
|
|
|
qDebug() << "After termination, lock file exists and gets removed.";
|
|
|
|
file.remove();
|
|
|
|
}
|
|
|
|
}
|
2012-08-26 13:47:45 +04:00
|
|
|
|
|
|
|
_errors.append( tr("The CSync thread terminated.") );
|
|
|
|
_csyncError = true;
|
|
|
|
qDebug() << "-> CSync Terminated!";
|
|
|
|
slotCSyncFinished();
|
2012-04-30 10:56:56 +04:00
|
|
|
}
|
|
|
|
|
2012-06-25 17:31:13 +04:00
|
|
|
void ownCloudFolder::slotLocalPathChanged( const QString& dir )
|
|
|
|
{
|
|
|
|
QDir notifiedDir(dir);
|
|
|
|
QDir localPath( path() );
|
|
|
|
|
2012-06-26 14:27:50 +04:00
|
|
|
if( notifiedDir.absolutePath() == localPath.absolutePath() ) {
|
2012-06-25 17:31:13 +04:00
|
|
|
if( !localPath.exists() ) {
|
|
|
|
qDebug() << "XXXXXXX The sync folder root was removed!!";
|
2012-08-26 13:47:45 +04:00
|
|
|
if( _thread && _thread->isRunning() ) {
|
2012-06-25 17:31:13 +04:00
|
|
|
qDebug() << "CSync currently running, set wipe flag!!";
|
|
|
|
} else {
|
|
|
|
qDebug() << "CSync not running, wipe it now!!";
|
|
|
|
wipe();
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "ALARM: The local path was DELETED!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 12:10:07 +04:00
|
|
|
// 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.
|
|
|
|
// See http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-788
|
|
|
|
void ownCloudFolder::wipe()
|
|
|
|
{
|
2012-10-29 14:23:41 +04:00
|
|
|
QString stateDbFile = path()+QLatin1String(".csync_journal.db");
|
|
|
|
|
|
|
|
QFile file(stateDbFile);
|
|
|
|
if( file.exists() ) {
|
|
|
|
if( !file.remove()) {
|
|
|
|
qDebug() << "WRN: Failed to remove existing csync StateDB " << stateDbFile;
|
2012-06-11 12:10:07 +04:00
|
|
|
} else {
|
2012-10-29 14:23:41 +04:00
|
|
|
qDebug() << "wipe: Removed csync StateDB " << stateDbFile;
|
2012-06-11 12:10:07 +04:00
|
|
|
}
|
2012-10-29 14:23:41 +04:00
|
|
|
} else {
|
|
|
|
qDebug() << "WRN: statedb is empty, can not remove.";
|
|
|
|
}
|
|
|
|
// Check if the tmp database file also exists
|
|
|
|
QString ctmpName = path() + QLatin1String(".csync_journal.db.ctmp");
|
|
|
|
QFile ctmpFile( ctmpName );
|
|
|
|
if( ctmpFile.exists() ) {
|
|
|
|
ctmpFile.remove();
|
2012-06-11 12:10:07 +04:00
|
|
|
}
|
2012-10-29 14:23:41 +04:00
|
|
|
_wipeDb = false;
|
2012-06-11 12:10:07 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 19:19:48 +04:00
|
|
|
ServerActionNotifier::ServerActionNotifier(QObject *parent)
|
|
|
|
: QObject(parent)
|
2012-12-12 22:30:28 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-14 19:19:48 +04:00
|
|
|
void ServerActionNotifier::slotSyncFinished(const SyncResult &result)
|
2012-12-12 22:30:28 +04:00
|
|
|
{
|
2013-02-14 19:19:48 +04:00
|
|
|
SyncFileItemVector items = result.syncFileItemVector();
|
|
|
|
if (items.count() == 0)
|
|
|
|
return;
|
2012-12-12 22:30:28 +04:00
|
|
|
|
2013-02-14 19:19:48 +04:00
|
|
|
int newItems = 0;
|
|
|
|
int removedItems = 0;
|
|
|
|
int updatedItems = 0;
|
|
|
|
SyncFileItem firstItemNew;
|
|
|
|
SyncFileItem firstItemDeleted;
|
|
|
|
SyncFileItem firstItemUpdated;
|
|
|
|
foreach (const SyncFileItem &item, items) {
|
|
|
|
if (item._dir == SyncFileItem::Down) {
|
|
|
|
switch (item._instruction) {
|
|
|
|
case CSYNC_INSTRUCTION_NEW:
|
|
|
|
newItems++;
|
|
|
|
if (firstItemNew.isEmpty())
|
|
|
|
firstItemNew = item;
|
|
|
|
break;
|
|
|
|
case CSYNC_INSTRUCTION_REMOVE:
|
|
|
|
removedItems++;
|
|
|
|
if (firstItemDeleted.isEmpty())
|
|
|
|
firstItemDeleted = item;
|
|
|
|
break;
|
|
|
|
case CSYNC_INSTRUCTION_UPDATED:
|
|
|
|
updatedItems++;
|
|
|
|
if (firstItemUpdated.isEmpty())
|
|
|
|
firstItemUpdated = item;
|
2013-02-21 16:36:33 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// nothing.
|
|
|
|
break;
|
2013-02-14 19:19:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newItems > 0) {
|
|
|
|
QString file = QDir::toNativeSeparators(firstItemNew._file);
|
|
|
|
if (newItems == 1)
|
|
|
|
emit guiLog(tr("New file available"), tr("'%1' has been synced to this machine.").arg(file));
|
|
|
|
else
|
|
|
|
emit guiLog(tr("New files available"), tr("'%1' and %n other file(s) have been synced to this machine.",
|
|
|
|
"", newItems-1).arg(file));
|
|
|
|
}
|
|
|
|
if (removedItems > 0) {
|
|
|
|
QString file = QDir::toNativeSeparators(firstItemDeleted._file);
|
|
|
|
if (removedItems == 1)
|
|
|
|
emit guiLog(tr("File removed"), tr("'%1' has been removed.").arg(file));
|
|
|
|
else
|
2013-04-16 13:24:07 +04:00
|
|
|
emit guiLog(tr("Files removed"), tr("'%1' and %n other file(s) have been removed.",
|
2013-02-14 19:19:48 +04:00
|
|
|
"", removedItems-1).arg(file));
|
|
|
|
}
|
|
|
|
if (updatedItems > 0) {
|
|
|
|
QString file = QDir::toNativeSeparators(firstItemUpdated._file);
|
|
|
|
if (updatedItems == 1)
|
2013-04-16 13:24:07 +04:00
|
|
|
emit guiLog(tr("File updated"), tr("'%1' has been updated.").arg(file));
|
2013-02-14 19:19:48 +04:00
|
|
|
else
|
2013-04-16 13:24:07 +04:00
|
|
|
emit guiLog(tr("Files updated"), tr("'%1' and %n other file(s) have been updated.",
|
2013-02-14 19:19:48 +04:00
|
|
|
"", updatedItems-1).arg(file));
|
|
|
|
}
|
2012-12-12 22:30:28 +04:00
|
|
|
}
|
|
|
|
|
2012-02-15 17:44:09 +04:00
|
|
|
} // ns
|
|
|
|
|