bool Folder::init() { Account *account = AccountManager::instance()->account(); if (!account) { // Normaly this should not happen, but it could be that there is something // wrong with the config and it is better not to crash. qWarning() << "WRN: No account configured, can't sync"; return false; } // We need to reconstruct the url because the path need to be fully decoded, as csync will re-encode the path: // Remember that csync will just append the filename to the path and pass it to the vio plugin. // csync_owncloud will then re-encode everything. #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QUrl url = remoteUrl(); QString url_string = url.scheme() + QLatin1String("://") + url.authority(QUrl::EncodeDelimiters) + url.path(QUrl::FullyDecoded); #else // Qt4 was broken anyway as it did not encode the '#' as it should have done (it was actually a provlem when parsing the path from QUrl::setPath QString url_string = remoteUrl().toString(); #endif url_string = Utility::toCSyncScheme(url_string); QString localpath = path(); if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url_string.toUtf8().data() ) < 0 ) { qDebug() << "Unable to create csync-context!"; slotSyncError(tr("Unable to create csync-context")); _csync_ctx = 0; } else { csync_set_log_callback( csyncLogCatcher ); csync_set_log_level( 11 ); if (Account *account = AccountManager::instance()->account()) { account->credentials()->syncContextPreInit(_csync_ctx); } else { qDebug() << Q_FUNC_INFO << "No default Account object, huh?"; } if( csync_init( _csync_ctx ) < 0 ) { qDebug() << "Could not initialize csync!" << csync_get_status(_csync_ctx) << csync_get_status_string(_csync_ctx); QString errStr = SyncEngine::csyncErrorToString(CSYNC_STATUS(csync_get_status(_csync_ctx))); const char *errMsg = csync_get_status_string(_csync_ctx); if( errMsg ) { errStr += QLatin1String("<br/>"); errStr += QString::fromUtf8(errMsg); } slotSyncError(errStr); csync_destroy(_csync_ctx); _csync_ctx = 0; } } return _csync_ctx; }
bool Folder::init() { // We need to reconstruct the url because the path needs to be fully decoded, as csync will re-encode the path: // Remember that csync will just append the filename to the path and pass it to the vio plugin. // csync_owncloud will then re-encode everything. #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QUrl url = remoteUrl(); QString url_string = url.scheme() + QLatin1String("://") + url.authority(QUrl::EncodeDelimiters) + url.path(QUrl::FullyDecoded); #else // Qt4 was broken anyway as it did not encode the '#' as it should have done (it was actually a problem when parsing the path from QUrl::setPath QString url_string = remoteUrl().toString(); #endif url_string = Utility::toCSyncScheme(url_string); QString localpath = path(); if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url_string.toUtf8().data() ) < 0 ) { qDebug() << "Unable to create csync-context!"; slotSyncError(tr("Unable to create csync-context")); _csync_ctx = 0; } else { csync_set_log_callback( csyncLogCatcher ); csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 ); Q_ASSERT( _accountState ); if( csync_init( _csync_ctx ) < 0 ) { qDebug() << "Could not initialize csync!" << csync_get_status(_csync_ctx) << csync_get_status_string(_csync_ctx); QString errStr = SyncEngine::csyncErrorToString(CSYNC_STATUS(csync_get_status(_csync_ctx))); const char *errMsg = csync_get_status_string(_csync_ctx); if( errMsg ) { errStr += QLatin1String("<br/>"); errStr += QString::fromUtf8(errMsg); } slotSyncError(errStr); csync_destroy(_csync_ctx); _csync_ctx = 0; } } return _csync_ctx; }
void Folder::startSync(const QStringList &pathList) { Q_ASSERT(_accountState); Q_UNUSED(pathList) if (!_csync_ctx) { // no _csync_ctx yet, initialize it. init(); if (!_csync_ctx) { qDebug() << Q_FUNC_INFO << "init failed."; // the error should already be set QMetaObject::invokeMethod(this, "slotSyncFinished", Qt::QueuedConnection); return; } } else if (proxyDirty()) { setProxyDirty(false); } csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 ); if (isBusy()) { qCritical() << "* ERROR csync is still running and new sync requested."; return; } _errors.clear(); _csyncError = false; _csyncUnavail = false; _timeSinceLastSyncStart.restart(); _syncResult.clearErrors(); _syncResult.setStatus( SyncResult::SyncPrepare ); _syncResult.setSyncFileItemVector(SyncFileItemVector()); emit syncStateChange(); qDebug() << "*** Start syncing " << alias() << " - client version" << qPrintable(Theme::instance()->version()); if (! setIgnoredFiles()) { slotSyncError(tr("Could not read system exclude file")); QMetaObject::invokeMethod(this, "slotSyncFinished", Qt::QueuedConnection); return; } // pass the setting if hidden files are to be ignored, will be read in csync_update _csync_ctx->ignore_hidden_files = _definition.ignoreHiddenFiles; _engine.reset(new SyncEngine( _accountState->account(), _csync_ctx, path(), remoteUrl().path(), remotePath(), &_journal)); qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector"); qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction"); connect(_engine.data(), SIGNAL(rootEtag(QString)), this, SLOT(etagRetreivedFromSyncEngine(QString))); connect( _engine.data(), SIGNAL(treeWalkResult(const SyncFileItemVector&)), this, SLOT(slotThreadTreeWalkResult(const SyncFileItemVector&)), Qt::QueuedConnection); connect( _engine.data(), SIGNAL(aboutToPropagate(SyncFileItemVector&)), this, SLOT(slotAboutToPropagate(SyncFileItemVector&))); connect(_engine.data(), SIGNAL(started()), SLOT(slotSyncStarted()), Qt::QueuedConnection); connect(_engine.data(), SIGNAL(finished(bool)), SLOT(slotSyncFinished(bool)), Qt::QueuedConnection); connect(_engine.data(), SIGNAL(csyncError(QString)), SLOT(slotSyncError(QString)), Qt::QueuedConnection); connect(_engine.data(), SIGNAL(csyncUnavailable()), SLOT(slotCsyncUnavailable()), Qt::QueuedConnection); //direct connection so the message box is blocking the sync. connect(_engine.data(), SIGNAL(aboutToRemoveAllFiles(SyncFileItem::Direction,bool*)), SLOT(slotAboutToRemoveAllFiles(SyncFileItem::Direction,bool*))); connect(_engine.data(), SIGNAL(folderDiscovered(bool,QString)), this, SLOT(slotFolderDiscovered(bool,QString))); connect(_engine.data(), SIGNAL(transmissionProgress(ProgressInfo)), this, SLOT(slotTransmissionProgress(ProgressInfo))); connect(_engine.data(), SIGNAL(itemCompleted(const SyncFileItem &, const PropagatorJob &)), this, SLOT(slotItemCompleted(const SyncFileItem &, const PropagatorJob &))); connect(_engine.data(), SIGNAL(syncItemDiscovered(const SyncFileItem &)), this, SLOT(slotSyncItemDiscovered(const SyncFileItem &))); connect(_engine.data(), SIGNAL(newBigFolder(QString)), this, SLOT(slotNewBigFolderDiscovered(QString))); setDirtyNetworkLimits(); ConfigFile cfgFile; auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); quint64 limit = newFolderLimit.first ? newFolderLimit.second * 1000 * 1000 : -1; // convert from MB to B _engine->setNewBigFolderSizeLimit(limit); QMetaObject::invokeMethod(_engine.data(), "startSync", Qt::QueuedConnection); // disable events until syncing is done // _watcher->setEventsEnabled(false); emit syncStarted(); }
void Folder::bubbleUpSyncResult() { // count new, removed and updated items int newItems = 0; int removedItems = 0; int updatedItems = 0; int ignoredItems = 0; int renamedItems = 0; int errorItems = 0; SyncFileItemPtr firstItemNew; SyncFileItemPtr firstItemDeleted; SyncFileItemPtr firstItemUpdated; SyncFileItemPtr firstItemRenamed; SyncFileItemPtr firstItemError; SyncRunFileLog syncFileLog; syncFileLog.start(path(), _engine ? _engine->stopWatch() : Utility::StopWatch() ); QElapsedTimer timer; timer.start(); foreach (const SyncFileItemPtr &item, _syncResult.syncFileItemVector() ) { // Log the item syncFileLog.logItem( *item ); // and process the item to the gui if( item->_status == SyncFileItem::FatalError || item->_status == SyncFileItem::NormalError ) { slotSyncError( tr("%1: %2").arg(item->_file, item->_errorString) ); errorItems++; if (!firstItemError) { firstItemError = item; } } else if( item->_status == SyncFileItem::FileIgnored ) { // ignored files don't show up in notifications continue; } else { // add new directories or remove gone away dirs to the watcher if (item->_isDirectory && item->_instruction == CSYNC_INSTRUCTION_NEW ) { FolderMan::instance()->addMonitorPath( alias(), path()+item->_file ); } if (item->_isDirectory && item->_instruction == CSYNC_INSTRUCTION_REMOVE ) { FolderMan::instance()->removeMonitorPath( alias(), path()+item->_file ); } if (!item->hasErrorStatus() && item->_direction == SyncFileItem::Down) { switch (item->_instruction) { case CSYNC_INSTRUCTION_NEW: newItems++; if (!firstItemNew) firstItemNew = item; break; case CSYNC_INSTRUCTION_REMOVE: removedItems++; if (!firstItemDeleted) firstItemDeleted = item; break; case CSYNC_INSTRUCTION_CONFLICT: case CSYNC_INSTRUCTION_SYNC: if (!item->_isDirectory) { updatedItems++; if (!firstItemUpdated) firstItemUpdated = item; } break; case CSYNC_INSTRUCTION_ERROR: qDebug() << "Got Instruction ERROR. " << _syncResult.errorString(); break; case CSYNC_INSTRUCTION_RENAME: if (!firstItemRenamed) { firstItemRenamed = item; } renamedItems++; break; default: // nothing. break; } } else if( item->_direction == SyncFileItem::None ) { // ignored files counting. if( item->_instruction == CSYNC_INSTRUCTION_IGNORE ) { ignoredItems++; } } } } syncFileLog.close(); qDebug() << "Processing result list and logging took " << timer.elapsed() << " Milliseconds."; _syncResult.setWarnCount(ignoredItems); if( firstItemNew ) { createGuiLog( firstItemNew->_file, SyncFileStatus::STATUS_NEW, newItems ); } if( firstItemDeleted ) { createGuiLog( firstItemDeleted->_file, SyncFileStatus::STATUS_REMOVE, removedItems ); } if( firstItemUpdated ) { createGuiLog( firstItemUpdated->_file, SyncFileStatus::STATUS_UPDATED, updatedItems ); } if( firstItemRenamed ) { SyncFileStatus status(SyncFileStatus::STATUS_RENAME); // if the path changes it's rather a move QDir renTarget = QFileInfo(firstItemRenamed->_renameTarget).dir(); QDir renSource = QFileInfo(firstItemRenamed->_file).dir(); if(renTarget != renSource) { status.set(SyncFileStatus::STATUS_MOVE); } createGuiLog( firstItemRenamed->_file, status, renamedItems, firstItemRenamed->_renameTarget ); } createGuiLog( firstItemError->_file, SyncFileStatus::STATUS_ERROR, errorItems ); qDebug() << "OO folder slotSyncFinished: result: " << int(_syncResult.status()); }