Make owncloudcmd work with the parallel upload/download

Also make it work when there syncing a remote subfolder
This commit is contained in:
Olivier Goffart 2014-02-17 17:31:03 +01:00
parent a4ee8d6f6f
commit a39caa1cda
6 changed files with 43 additions and 15 deletions

View file

@ -56,12 +56,13 @@ void csyncLogCatcher(int /*verbosity*/,
/* static variables to hold the credentials */
QMutex CSyncThread::_syncMutex;
CSyncThread::CSyncThread(CSYNC *csync, const QString &localPath, const QString &remotePath, SyncJournalDb *journal)
CSyncThread::CSyncThread(CSYNC *ctx, const QString& localPath, const QString& remoteURL, const QString& remotePath, Mirall::SyncJournalDb* journal)
:_previousIndex(-1)
{
_localPath = localPath;
_remotePath = remotePath;
_csync_ctx = csync;
_remoteUrl = remoteURL;
_csync_ctx = ctx;
_journal = journal;
qRegisterMetaType<SyncFileItem>("SyncFileItem");
qRegisterMetaType<SyncFileItem::Status>("SyncFileItem::Status");
@ -556,7 +557,7 @@ void CSyncThread::slotUpdateFinished(int updateResult)
csync_set_module_property(_csync_ctx, "get_dav_session", &session);
Q_ASSERT(session);
_propagator.reset(new OwncloudPropagator (session, _localPath, _remotePath,
_propagator.reset(new OwncloudPropagator (session, _localPath, _remoteUrl, _remotePath,
_journal, &_thread));
connect(_propagator.data(), SIGNAL(completed(SyncFileItem)),
this, SLOT(transferCompleted(SyncFileItem)), Qt::QueuedConnection);

View file

@ -48,7 +48,7 @@ class CSyncThread : public QObject
Q_OBJECT
public:
CSyncThread(CSYNC *, const QString &localPath, const QString &remotePath, SyncJournalDb *journal);
CSyncThread(CSYNC *, const QString &localPath, const QString &remoteURL, const QString &remotePath, SyncJournalDb *journal);
~CSyncThread();
static QString csyncErrorToString( CSYNC_STATUS);
@ -100,6 +100,7 @@ private:
CSYNC *_csync_ctx;
bool _needsUpdate;
QString _localPath;
QString _remoteUrl;
QString _remotePath;
SyncJournalDb *_journal;
QScopedPointer <OwncloudPropagator> _propagator;

View file

@ -552,7 +552,7 @@ void Folder::startSync(const QStringList &pathList)
qDebug() << "*** Start syncing";
setIgnoredFiles();
_csync = new CSyncThread( _csync_ctx, path(), remoteUrl().path(), &_journal);
_csync = new CSyncThread( _csync_ctx, path(), remoteUrl().path(), _remotePath, &_journal);
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");

View file

@ -165,19 +165,25 @@ class OwncloudPropagator : public QObject {
QScopedPointer<PropagateDirectory> _rootJob;
public:
/* 'const' because they are accessed by the thread */
QThread* _neonThread;
ne_session_s *_session;
ne_session_s * const _session;
const QString _localDir; // absolute path to the local directory. ends with '/'
const QString _remoteDir; // path to the root of the remote. ends with '/'
SyncJournalDb *_journal;
const QString _remoteDir; // path to the root of the remote. ends with '/' (include remote.php/webdav)
const QString _remoteFolder; // folder. (same as remoteDir but without remote.php/webdav)
SyncJournalDb * const _journal;
public:
OwncloudPropagator(ne_session_s *session, const QString &localDir, const QString &remoteDir,
OwncloudPropagator(ne_session_s *session, const QString &localDir, const QString &remoteDir, const QString &remoteFolder,
SyncJournalDb *progressDb, QThread *neonThread)
: _neonThread(neonThread)
, _session(session)
, _localDir((localDir.endsWith(QChar('/'))) ? localDir : localDir+'/' )
, _remoteDir((remoteDir.endsWith(QChar('/'))) ? remoteDir : remoteDir+'/' )
, _localDir((localDir.endsWith(QChar('/'))) ? localDir : localDir+'/' )
, _remoteDir((remoteDir.endsWith(QChar('/'))) ? remoteDir : remoteDir+'/' )
, _remoteFolder((remoteFolder.endsWith(QChar('/'))) ? remoteFolder : remoteFolder+'/' )
, _journal(progressDb)
, _activeJobs(0)
{ }
@ -203,6 +209,8 @@ public:
_rootJob->abort();
emit finished();
}
signals:
void completed(const SyncFileItem &);
void progress(Progress::Kind kind, const SyncFileItem&, quint64 bytes, quint64 total);

View file

@ -145,7 +145,7 @@ void PropagateUploadFileQNAM::startNextChunk()
device = _file;
}
_job = new PUTFileJob(AccountManager::instance()->account(), path, device, headers);
_job = new PUTFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + path, device, headers);
connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished()));
_job->start();
}
@ -382,7 +382,7 @@ void PropagateDownloadFileQNAM::start()
qDebug() << "Retry with range " << headers["Range"];
}
_job = new GETFileJob(AccountManager::instance()->account(), _item._file, &_tmpFile, headers);
_job = new GETFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + _item._file, &_tmpFile, headers);
connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotGetFinished()));
_propagator->_activeJobs ++;
_job->start();

View file

@ -27,10 +27,13 @@
#include "logger.h"
#include "csync.h"
#include "mirall/clientproxy.h"
#include "account.h"
#include <creds/httpcredentials.h>
using namespace Mirall;
int getauth(const char* prompt, char* buf, size_t len, int echo, int verify, void*)
int getauth(const char* prompt, char* buf, size_t len, int, int, void*)
{
std::cout << "** Authentication required: \n" << prompt << std::endl;
std::string s;
@ -115,6 +118,21 @@ int main(int argc, char **argv) {
parseOptions( app.arguments(), &options );
QUrl url(options.target_url.toUtf8());
Account account;
// Find the folder and the original owncloud url
QStringList splitted = url.path().split(Account::davPath());
url.setPath(splitted.value(0));
url.setScheme(url.scheme().replace("owncloud", "http"));
QString folder = splitted.value(1);
account.setUrl(url);
account.setCredentials(new HttpCredentials(url.userName(), url.password()));
AccountManager::instance()->setAccount(&account);
CSYNC *_csync_ctx;
if( csync_create( &_csync_ctx, options.source_dir.toUtf8(),
options.target_url.toUtf8()) < 0 ) {
@ -175,7 +193,7 @@ int main(int argc, char **argv) {
}
SyncJournalDb db(options.source_dir);
CSyncThread csyncthread(_csync_ctx, options.source_dir, QUrl(options.target_url).path(), &db);
CSyncThread csyncthread(_csync_ctx, options.source_dir, QUrl(options.target_url).path(), folder, &db);
QObject::connect(&csyncthread, SIGNAL(finished()), &app, SLOT(quit()));
csyncthread.startSync();