mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 21:46:03 +03:00
Port the propagate mkdir to QNAM
This way we can make it parallel
This commit is contained in:
parent
7246011b62
commit
1310bef528
8 changed files with 164 additions and 97 deletions
|
@ -53,6 +53,7 @@ set(libsync_SRCS
|
|||
propagateupload.cpp
|
||||
propagateremotedelete.cpp
|
||||
propagateremotemove.cpp
|
||||
propagateremotemkdir.cpp
|
||||
quotainfo.cpp
|
||||
syncengine.cpp
|
||||
syncfilestatus.cpp
|
||||
|
|
|
@ -497,7 +497,11 @@ void PropfindJob::start()
|
|||
req.setRawHeader("Depth", "0");
|
||||
QByteArray propStr;
|
||||
foreach (const QByteArray &prop, properties) {
|
||||
propStr += " <d:" + prop + " />\n";
|
||||
if (prop.contains(':')) {
|
||||
propStr += " <" + prop + " />\n";
|
||||
} else {
|
||||
propStr += " <d:" + prop + " />\n";
|
||||
}
|
||||
}
|
||||
QByteArray xml = "<?xml version=\"1.0\" ?>\n"
|
||||
"<d:propfind xmlns:d=\"DAV:\">\n"
|
||||
|
@ -540,15 +544,13 @@ bool PropfindJob::finished()
|
|||
|
||||
while (!reader.atEnd()) {
|
||||
QXmlStreamReader::TokenType type = reader.readNext();
|
||||
if (type == QXmlStreamReader::StartElement &&
|
||||
reader.namespaceUri() == QLatin1String("DAV:")) {
|
||||
if (type == QXmlStreamReader::StartElement) {
|
||||
if (curElement.isEmpty()) {
|
||||
curElement.push(reader.name().toString());
|
||||
items.insert(reader.name().toString(), reader.text().toString());
|
||||
}
|
||||
}
|
||||
if (type == QXmlStreamReader::EndElement &&
|
||||
reader.namespaceUri() == QLatin1String("DAV:")) {
|
||||
if (type == QXmlStreamReader::EndElement) {
|
||||
if(curElement.top() == reader.name()) {
|
||||
curElement.pop();
|
||||
}
|
||||
|
@ -559,6 +561,7 @@ bool PropfindJob::finished()
|
|||
} else {
|
||||
qDebug() << "Quota request *not* successful, http result code is" << http_result_code
|
||||
<< (http_result_code == 302 ? reply()->header(QNetworkRequest::LocationHeader).toString() : QLatin1String(""));
|
||||
emit finishedWithError();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -158,6 +158,7 @@ public:
|
|||
|
||||
signals:
|
||||
void result(const QVariantMap &values);
|
||||
void finishedWithError();
|
||||
|
||||
private slots:
|
||||
virtual bool finished() Q_DECL_OVERRIDE;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "propagateupload.h"
|
||||
#include "propagateremotedelete.h"
|
||||
#include "propagateremotemove.h"
|
||||
#include "propagateremotemkdir.h"
|
||||
#include "propagatorjobs.h"
|
||||
#include "propagator_legacy.h"
|
||||
#include "mirallconfigfile.h"
|
||||
|
|
117
src/libsync/propagateremotemkdir.cpp
Normal file
117
src/libsync/propagateremotemkdir.cpp
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (C) by Olivier Goffart <ogoffart@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.
|
||||
*/
|
||||
|
||||
#include "propagateremotemkdir.h"
|
||||
#include "owncloudpropagator_p.h"
|
||||
#include "account.h"
|
||||
#include "syncjournalfilerecord.h"
|
||||
#include <QFile>
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
void PropagateRemoteMkdir::start()
|
||||
{
|
||||
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
|
||||
return;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << _item._file;
|
||||
|
||||
_job = new MkColJob(AccountManager::instance()->account(),
|
||||
_propagator->_remoteFolder + _item._file,
|
||||
this);
|
||||
connect(_job, SIGNAL(finished(QNetworkReply::NetworkError)), this, SLOT(slotMkcolJobFinished()));
|
||||
_propagator->_activeJobs++;
|
||||
_job->start();
|
||||
emitReady();
|
||||
}
|
||||
|
||||
void PropagateRemoteMkdir::abort()
|
||||
{
|
||||
if (_job && _job->reply())
|
||||
_job->reply()->abort();
|
||||
}
|
||||
|
||||
void PropagateRemoteMkdir::slotMkcolJobFinished()
|
||||
{
|
||||
_propagator->_activeJobs--;
|
||||
|
||||
Q_ASSERT(_job);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << _job->reply()->request().url() << "FINISHED WITH STATUS"
|
||||
<< _job->reply()->error()
|
||||
<< (_job->reply()->error() == QNetworkReply::NoError ? QLatin1String("") : _job->reply()->errorString());
|
||||
|
||||
QNetworkReply::NetworkError err = _job->reply()->error();
|
||||
_item._httpErrorCode = _job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
if (_item._httpErrorCode == 405) {
|
||||
// This happens when the directory already exist. Nothing to do.
|
||||
} else if (err != QNetworkReply::NoError) {
|
||||
SyncFileItem::Status status = classifyError(err, _item._httpErrorCode);
|
||||
done(status, _job->reply()->errorString());
|
||||
return;
|
||||
} else if (_item._httpErrorCode != 201) {
|
||||
// Normaly we expect "201 Created"
|
||||
// If it is not the case, it might be because of a proxy or gateway intercepting the request, so we must
|
||||
// throw an error.
|
||||
done(SyncFileItem::NormalError, tr("Wrong HTTP code returned by server. Expected 201, but recieved \"%1 %2\".")
|
||||
.arg(_item._httpErrorCode).arg(_job->reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
_item._requestDuration = _job->duration();
|
||||
_item._responseTimeStamp = _job->responseTimestamp();
|
||||
_item._fileId = _job->reply()->rawHeader("OC-FileId");
|
||||
|
||||
if (_item._fileId.isEmpty()) {
|
||||
// Owncloud 7.0.0 and before did not have a header with the file id.
|
||||
// (https://github.com/owncloud/core/issues/9000)
|
||||
// So we must get the file id using a PROPFIND
|
||||
// This is required so that we can detect moves even if the folder is renamed on the server
|
||||
// while files are still uploading
|
||||
_propagator->_activeJobs++;
|
||||
auto propfindJob = new PropfindJob(_job->account(), _job->path(), this);
|
||||
propfindJob->setProperties(QList<QByteArray>() << "getetag" << "http://owncloud.org/ns:id");
|
||||
QObject::connect(propfindJob, SIGNAL(result(QVariantMap)), this, SLOT(propfindResult(QVariantMap)));
|
||||
QObject::connect(propfindJob, SIGNAL(finishedWithError()), this, SLOT(propfindError()));
|
||||
propfindJob->start();
|
||||
_job = propfindJob;
|
||||
return;
|
||||
}
|
||||
|
||||
done(SyncFileItem::Success);
|
||||
}
|
||||
|
||||
void PropagateRemoteMkdir::propfindResult(const QVariantMap &result)
|
||||
{
|
||||
_propagator->_activeJobs--;
|
||||
if (result.contains("getetag")) {
|
||||
_item._etag = result["getetag"].toByteArray();
|
||||
}
|
||||
if (result.contains("id")) {
|
||||
_item._fileId = result["id"].toByteArray();
|
||||
}
|
||||
done(SyncFileItem::Success);
|
||||
}
|
||||
|
||||
void PropagateRemoteMkdir::propfindError()
|
||||
{
|
||||
// ignore the PROPFIND error
|
||||
_propagator->_activeJobs--;
|
||||
done(SyncFileItem::Success);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
36
src/libsync/propagateremotemkdir.h
Normal file
36
src/libsync/propagateremotemkdir.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) by Olivier Goffart <ogoffart@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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "owncloudpropagator.h"
|
||||
#include "networkjobs.h"
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
class PropagateRemoteMkdir : public PropagateItemJob {
|
||||
Q_OBJECT
|
||||
QPointer<AbstractNetworkJob> _job;
|
||||
friend class PropagateDirectory; // So it can access the _item;
|
||||
public:
|
||||
PropagateRemoteMkdir (OwncloudPropagator* propagator,const SyncFileItem& item)
|
||||
: PropagateItemJob(propagator, item) {}
|
||||
void start() Q_DECL_OVERRIDE;
|
||||
void abort() Q_DECL_OVERRIDE;
|
||||
private slots:
|
||||
void slotMkcolJobFinished();
|
||||
void propfindResult(const QVariantMap &);
|
||||
void propfindError();
|
||||
};
|
||||
|
||||
}
|
|
@ -135,88 +135,6 @@ void PropagateLocalMkdir::start()
|
|||
done(SyncFileItem::Success);
|
||||
}
|
||||
|
||||
/* The list of properties that is fetched in PropFind after a MKCOL */
|
||||
static const ne_propname ls_props[] = {
|
||||
{ "DAV:", "getetag"},
|
||||
{ "http://owncloud.org/ns", "id"},
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* Parse the PROPFIND result after a MKCOL
|
||||
*/
|
||||
void PropagateRemoteMkdir::propfind_results(void *userdata,
|
||||
const ne_uri *uri,
|
||||
const ne_prop_result_set *set)
|
||||
{
|
||||
PropagateRemoteMkdir *job = static_cast<PropagateRemoteMkdir *>(userdata);
|
||||
|
||||
job->_item._etag = parseEtag(ne_propset_value( set, &ls_props[0] ));
|
||||
|
||||
const char* fileId = ne_propset_value( set, &ls_props[1] );
|
||||
if (fileId) {
|
||||
job->_item._fileId = fileId;
|
||||
qDebug() << "MKCOL: " << uri << " FileID set it to " << fileId;
|
||||
|
||||
// save the file id already so we can detect rename
|
||||
SyncJournalFileRecord record(job->_item, job->_propagator->_localDir + job->_item._renameTarget);
|
||||
job->_propagator->_journal->setFileRecord(record);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Called after the headers have been recieved, try to extract the fileId
|
||||
*/
|
||||
void PropagateRemoteMkdir::post_headers(ne_request* req, void* userdata, const ne_status* )
|
||||
{
|
||||
const char *header = ne_get_response_header(req, "OC-FileId");
|
||||
if( header ) {
|
||||
qDebug() << "MKCOL: " << static_cast<PropagateRemoteMkdir*>(userdata)->_item._file << " FileID from header:" << header;
|
||||
static_cast<PropagateRemoteMkdir*>(userdata)->_item._fileId = header;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PropagateRemoteMkdir::start()
|
||||
{
|
||||
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
|
||||
return;
|
||||
|
||||
QScopedPointer<char, QScopedPointerPodDeleter> uri(
|
||||
ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8()));
|
||||
|
||||
ne_hook_post_headers(_propagator->_session, post_headers, this);
|
||||
|
||||
int rc = ne_mkcol(_propagator->_session, uri.data());
|
||||
|
||||
ne_unhook_post_headers(_propagator->_session, post_headers, this);
|
||||
|
||||
|
||||
/* Special for mkcol: it returns 405 if the directory already exists.
|
||||
* Ignore that error */
|
||||
// Wed, 15 Nov 1995 06:25:24 GMT
|
||||
QDateTime dt = QDateTime::currentDateTimeUtc();
|
||||
_item._responseTimeStamp = dt.toString("hh:mm:ss");
|
||||
|
||||
if( updateErrorFromSession( rc , 0, 405 ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_item._fileId.isEmpty()) {
|
||||
// Owncloud 7.0.0 and before did not have a header with the file id.
|
||||
// (https://github.com/owncloud/core/issues/9000)
|
||||
// So we must get the file id using a PROPFIND
|
||||
// This is required so that wa can detect moves even if the folder is renamed on the server
|
||||
// while files are still uploading
|
||||
ne_propfind_handler *hdl = ne_propfind_create(_propagator->_session, uri.data(), 0);
|
||||
ne_propfind_named(hdl, ls_props, propfind_results, this);
|
||||
ne_propfind_destroy(hdl);
|
||||
}
|
||||
|
||||
done(SyncFileItem::Success);
|
||||
}
|
||||
|
||||
|
||||
void PropagateLocalRename::start()
|
||||
{
|
||||
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
|
||||
|
|
|
@ -83,16 +83,6 @@ public:
|
|||
void start() Q_DECL_OVERRIDE;
|
||||
|
||||
};
|
||||
class PropagateRemoteMkdir : public PropagateNeonJob {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PropagateRemoteMkdir (OwncloudPropagator* propagator,const SyncFileItem& item) : PropagateNeonJob(propagator, item) {}
|
||||
void start() Q_DECL_OVERRIDE;
|
||||
private:
|
||||
static void propfind_results(void *userdata, const ne_uri *uri, const ne_prop_result_set *set);
|
||||
static void post_headers(ne_request *req, void *userdata, const ne_status *status);
|
||||
friend class PropagateDirectory; // So it can access the _item;
|
||||
};
|
||||
class PropagateLocalRename : public PropagateItemJob {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue