bool ownCloudFolder::init() { QString url = replaceScheme(ownCloudInfo::instance()->webdavUrl() + secondPath()); QString localpath = path(); if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url.toUtf8().data() ) < 0 ) { qDebug() << "Unable to create csync-context!"; slotCSyncError(tr("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_get_error(_csync_ctx) << csync_get_error_string(_csync_ctx); slotCSyncError(CSyncThread::csyncErrorToString(csync_get_error(_csync_ctx), csync_get_error_string(_csync_ctx))); csync_destroy(_csync_ctx); _csync_ctx = 0; } setProxy(); } return _csync_ctx; }
bool Folder::init() { QString url = Utility::toCSyncScheme(ownCloudInfo::instance()->webdavUrl() + secondPath()); QString localpath = path(); if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url.toUtf8().data() ) < 0 ) { qDebug() << "Unable to create csync-context!"; slotCSyncError(tr("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); setIgnoredFiles(); cfgFile.getCredentials()->syncContextPreInit(_csync_ctx); if( csync_init( _csync_ctx ) < 0 ) { qDebug() << "Could not initialize csync!" << csync_get_error(_csync_ctx) << csync_get_error_string(_csync_ctx); slotCSyncError(CSyncThread::csyncErrorToString(csync_get_error(_csync_ctx), csync_get_error_string(_csync_ctx))); csync_destroy(_csync_ctx); _csync_ctx = 0; } } return _csync_ctx; }
~CSyncRunScopeHelper() { csync_destroy(ctx); qDebug() << "CSync run took " << t.elapsed() << " Milliseconds"; emit(parent->finished()); parent->_syncMutex.unlock(); }
static void teardown_local(void **state) { (void) state; /* unused */ assert_int_equal(csync_destroy(csync),0 ); assert_int_equal(system("rm -rf /tmp/check_csync1"), 0); assert_int_equal(system("rm -rf /tmp/check_csync2"), 0); assert_int_equal(system("rm -rf /tmp/check_csync"), 0); printf("********** tearing down local\n"); }
static void check_csync_destroy_null(void **state) { int rc; (void) state; /* unused */ rc = csync_destroy(NULL); assert_int_equal(rc, -1); }
Folder::~Folder() { if( _engine ) { _engine->abort(); _engine.reset(0); } // Destroy csync here. csync_destroy(_csync_ctx); }
static void teardown(void **state) { CSYNC *csync = *state; int rc; rc = csync_destroy(csync); assert_int_equal(rc, 0); *state = NULL; }
ownCloudFolder::~ownCloudFolder() { if( _thread ) { _thread->quit(); csync_request_abort(_csync_ctx); _thread->wait(); } // Destroy csync here. csync_destroy(_csync_ctx); }
Folder::~Folder() { if( _thread ) { _csync->abort(); _thread->wait(); } delete _csync; // Destroy csync here. csync_destroy(_csync_ctx); }
Folder::~Folder() { if( _thread ) { _thread->quit(); csync_request_abort(_csync_ctx); _thread->wait(); } delete _csync; // Destroy csync here. csync_destroy(_csync_ctx); }
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; }
END_TEST START_TEST (check_csync_create) { fail_unless(csync_create(&csync, "/tmp/csync1", "/tmp/csync2") == 0, NULL); fail_unless(csync->options.max_depth == MAX_DEPTH, NULL); fail_unless(csync->options.max_time_difference == MAX_TIME_DIFFERENCE, NULL); fail_unless(strcmp(csync->options.config_dir, CSYNC_CONF_DIR) > 0, NULL); fail_unless(csync_destroy(csync) == 0, NULL); }
static void teardown(void **state) { CSYNC *csync = *state; int rc; rc = csync_destroy(csync); assert_int_equal(rc, 0); rc = system("rm -rf /tmp/check_csync1"); assert_int_equal(rc, 0); *state = NULL; }
static void check_csync_create(void **state) { CSYNC *csync; char confdir[1024] = {0}; int rc; (void) state; /* unused */ rc = csync_create(&csync, "/tmp/csync1", "/tmp/csync2"); assert_int_equal(rc, 0); rc = csync_destroy(csync); assert_int_equal(rc, 0); }
static void teardown(void **state) { CSYNC *csync = *state; int rc; rc = csync_destroy(csync); assert_int_equal(rc, 0); rc = chdir(wd_buffer); assert_int_equal(rc, 0); rc = system("rm -rf /tmp/csync_test/"); assert_int_equal(rc, 0); *state = NULL; }
static void teardown(void **state) { statevar *sv = (statevar*) *state; CSYNC *csync = sv->csync; int rc; output("================== Tearing down!\n"); rc = csync_destroy(csync); assert_int_equal(rc, 0); rc = _tchdir(wd_buffer); assert_int_equal(rc, 0); rc = wipe_testdir(); assert_int_equal(rc, 0); *state = NULL; }
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 CSyncThread::run() { CSYNC *csync; WalkStats *wStats = new WalkStats; QTime walkTime; wStats->sourcePath = 0; wStats->errorType = 0; wStats->eval = 0; wStats->removed = 0; wStats->renamed = 0; wStats->newFiles = 0; wStats->ignores = 0; wStats->sync = 0; wStats->seenFiles = 0; wStats->conflicts = 0; wStats->error = 0; _mutex.lock(); if( csync_create(&csync, _source.toLocal8Bit().data(), _target.toLocal8Bit().data()) < 0 ) { emit csyncError( tr("CSync create failed.") ); } // FIXME: Check if we really need this stringcopy! wStats->sourcePath = qstrdup( _source.toLocal8Bit().constData() ); _mutex.unlock(); qDebug() << "## CSync Thread local only: " << _localCheckOnly; csync_set_auth_callback( csync, getauth ); csync_enable_conflictcopys(csync); MirallConfigFile cfg; QString excludeList = cfg.excludeFile(); if( !excludeList.isEmpty() ) { qDebug() << "==== added CSync exclude List: " << excludeList.toAscii(); csync_add_exclude_list( csync, excludeList.toAscii() ); } QTime t; t.start(); _mutex.lock(); if( _localCheckOnly ) { csync_set_local_only( csync, true ); } _mutex.unlock(); if( csync_init(csync) < 0 ) { CSYNC_ERROR_CODE err = csync_errno(); QString errStr; switch( err ) { 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: errStr = tr("CSync failed to load the ownCloud module."); break; case CSYNC_ERR_TIMESKEW: errStr = tr("The system time between the local machine and the server differs " "too much. Please use a time syncronization service (ntp) on both machines."); 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; default: errStr = tr("An internal error number %1 happend.").arg( (int) err ); } qDebug() << " #### ERROR String emitted: " << errStr; emit csyncError(errStr); goto cleanup; } qDebug() << "############################################################### >>"; if( csync_update(csync) < 0 ) { emit csyncError(tr("CSync Update failed.")); goto cleanup; } qDebug() << "<<###############################################################"; csync_set_userdata(csync, wStats); walkTime.start(); if( csync_walk_local_tree(csync, &checkPermissions, 0) < 0 ) { qDebug() << "Error in treewalk."; if( wStats->errorType == WALK_ERROR_DIR_PERMS ) { emit csyncError(tr("The local filesystem has directories which are write protected.\n" "That prevents ownCloud from successful syncing.\n" "Please make sure that all directories are writeable.")); } else if( wStats->errorType == WALK_ERROR_WALK ) { emit csyncError(tr("CSync encountered an error while examining the file system.\n" "Syncing is not possible.")); } else if( wStats->errorType == WALK_ERROR_INSTRUCTIONS ) { emit csyncError(tr("CSync update generated a strange instruction.\n" "Please write a bug report.")); } emit csyncError(tr("Local filesystem problems. Better disable Syncing and check.")); goto cleanup; } qDebug() << " ..... Local walk finished: " << walkTime.elapsed(); // emit the treewalk results. Do not touch the wStats after this. emit treeWalkResult(wStats); _mutex.lock(); if( _localCheckOnly ) { _mutex.unlock(); // we have to go out here as its local check only. goto cleanup; } else { _mutex.unlock(); // check if we can write all over. if( csync_reconcile(csync) < 0 ) { emit csyncError(tr("CSync reconcile failed.")); goto cleanup; } if( csync_propagate(csync) < 0 ) { emit csyncError(tr("CSync propagate failed.")); goto cleanup; } } cleanup: csync_destroy(csync); /* * Attention: do not delete the wStat memory here. it is deleted in the * slot catching the signel treeWalkResult because this thread can faster * die than the slot has read out the data. */ qDebug() << "CSync run took " << t.elapsed() << " Milliseconds"; }
static void teardown_remote(void **state) { (void) state; /* unused */ assert_int_equal(csync_destroy(csync), 0); assert_int_equal(system("rm -rf /tmp/check_csync1"), 0); assert_int_equal(system("rm -rf /tmp/check_csync2"), 0); }
void CSyncThread::run() { CSYNC *csync; WalkStats *wStats = new WalkStats; QTime walkTime; wStats->sourcePath = 0; wStats->errorType = 0; wStats->eval = 0; wStats->removed = 0; wStats->renamed = 0; wStats->newFiles = 0; wStats->ignores = 0; wStats->sync = 0; wStats->seenFiles = 0; wStats->conflicts = 0; wStats->error = 0; wStats->dirPermErrors = 0; ProxyInfo *proxyInfo = new ProxyInfo; _mutex.lock(); proxyInfo->proxyType = qstrdup( _proxyType.toAscii().constData() ); proxyInfo->proxyHost = qstrdup( _proxyHost.toAscii().constData() ); proxyInfo->proxyPort = qstrdup( _proxyPort.toAscii().constData() ); proxyInfo->proxyUser = qstrdup( _proxyUser.toAscii().constData() ); proxyInfo->proxyPwd = qstrdup( _proxyPwd.toAscii().constData() ); if( csync_create(&csync, _source.toUtf8().data(), _target.toUtf8().data()) < 0 ) { emit csyncError( tr("CSync create failed.") ); } // FIXME: Check if we really need this stringcopy! wStats->sourcePath = qstrdup( _source.toUtf8().constData() ); _csyncConfigDir = QString::fromUtf8( csync_get_config_dir( csync )); _mutex.unlock(); qDebug() << "## CSync Thread local only: " << _localCheckOnly; csync_set_auth_callback( csync, getauth ); csync_enable_conflictcopys(csync); MirallConfigFile cfg; QString excludeList = cfg.excludeFile(); if( !excludeList.isEmpty() ) { qDebug() << "==== added CSync exclude List: " << excludeList.toAscii(); csync_add_exclude_list( csync, excludeList.toAscii() ); } QTime t; t.start(); _mutex.lock(); if( _localCheckOnly ) { csync_set_local_only( csync, true ); } csync_set_userdata(csync, (void*) proxyInfo); _mutex.unlock(); if( csync_init(csync) < 0 ) { CSYNC_ERROR_CODE err = csync_get_error( csync ); QString errStr; switch( err ) { 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_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_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>"); 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_REMOTE_CREATE: case CSYNC_ERR_REMOTE_STAT: errStr = tr("A remote file can not be written. Please check the remote access."); break; default: errStr = tr("An internal error number %1 happend.").arg( (int) err ); } qDebug() << " #### ERROR String emitted: " << errStr; emit csyncError(errStr); goto cleanup; } emitStateDb(csync); qDebug() << "#### Update start #################################################### >>"; if( csync_update(csync) < 0 ) { CSYNC_ERROR_CODE err = csync_get_error( csync ); QString errStr; switch( err ) { case CSYNC_ERR_PROXY: errStr = tr("CSync failed to reach the host. Either host or proxy settings are not valid."); break; default: errStr = tr("CSync Update failed."); break; } emit csyncError( errStr ); goto cleanup; } qDebug() << "<<#### Update end ###########################################################"; csync_set_userdata(csync, wStats); walkTime.start(); if( csync_walk_local_tree(csync, &checkPermissions, 0) < 0 ) { qDebug() << "Error in treewalk."; if( wStats->errorType == WALK_ERROR_WALK ) { emit csyncError(tr("CSync encountered an error while examining the file system.\n" "Syncing is not possible.")); } else if( wStats->errorType == WALK_ERROR_INSTRUCTIONS ) { emit csyncError(tr("CSync update generated a strange instruction.\n" "Please write a bug report.")); } emit csyncError(tr("Local filesystem problems. Better disable Syncing and check.")); goto cleanup; } else { // only warn, do not stop the sync process. if( wStats->errorType == WALK_ERROR_DIR_PERMS ) { emit csyncError(tr("The local filesystem has %1 write protected directories." "That can hinder successful syncing.<p/>" "Please make sure that all local directories are writeable.").arg(wStats->dirPermErrors)); } } // emit the treewalk results. Do not touch the wStats after this. emit treeWalkResult(wStats); _mutex.lock(); if( _localCheckOnly ) { _mutex.unlock(); qDebug() << " ..... Local only walk finished: " << walkTime.elapsed(); // we have to go out here as its local check only. goto cleanup; } else { _mutex.unlock(); // check if we can write all over. if( csync_reconcile(csync) < 0 ) { emit csyncError(tr("CSync reconcile failed.")); goto cleanup; } if( csync_propagate(csync) < 0 ) { emit csyncError(tr("CSync propagate failed.")); goto cleanup; } } cleanup: csync_destroy(csync); if( proxyInfo->proxyType ) free( proxyInfo->proxyType ); if( proxyInfo->proxyHost ) free( proxyInfo->proxyHost ); if( proxyInfo->proxyPort ) free( proxyInfo->proxyPort ); if( proxyInfo->proxyUser ) free( proxyInfo->proxyUser ); if( proxyInfo->proxyPwd ) free( proxyInfo->proxyPwd ); free( proxyInfo ); /* * Attention: do not delete the wStat memory here. it is deleted in the * slot catching the signel treeWalkResult because this thread can faster * die than the slot has read out the data. */ qDebug() << "CSync run took " << t.elapsed() << " Milliseconds"; }