mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 06:55:59 +03:00
Use byte array for etag
This commit is contained in:
parent
5a7fd3f316
commit
5b457a1663
11 changed files with 40 additions and 35 deletions
|
@ -104,6 +104,7 @@ public:
|
|||
ASSERT(!_isError);
|
||||
return _result;
|
||||
}
|
||||
|
||||
T operator*() &&
|
||||
{
|
||||
ASSERT(!_isError);
|
||||
|
@ -116,6 +117,12 @@ public:
|
|||
return &_result;
|
||||
}
|
||||
|
||||
const T &get() const
|
||||
{
|
||||
ASSERT(!_isError)
|
||||
return _result;
|
||||
}
|
||||
|
||||
const Error &error() const &
|
||||
{
|
||||
ASSERT(_isError);
|
||||
|
|
|
@ -353,7 +353,7 @@ void Folder::slotRunEtagJob()
|
|||
// The _requestEtagJob is auto deleting itself on finish. Our guard pointer _requestEtagJob will then be null.
|
||||
}
|
||||
|
||||
void Folder::etagRetrieved(const QString &etag, const QDateTime &tp)
|
||||
void Folder::etagRetrieved(const QByteArray &etag, const QDateTime &tp)
|
||||
{
|
||||
// re-enable sync if it was disabled because network was down
|
||||
FolderMan::instance()->setSyncEnabled(true);
|
||||
|
@ -367,7 +367,7 @@ void Folder::etagRetrieved(const QString &etag, const QDateTime &tp)
|
|||
_accountState->tagLastSuccessfullETagRequest(tp);
|
||||
}
|
||||
|
||||
void Folder::etagRetrievedFromSyncEngine(const QString &etag, const QDateTime &time)
|
||||
void Folder::etagRetrievedFromSyncEngine(const QByteArray &etag, const QDateTime &time)
|
||||
{
|
||||
qCInfo(lcFolder) << "Root etag from during sync:" << etag;
|
||||
accountState()->tagLastSuccessfullETagRequest(time);
|
||||
|
|
|
@ -376,8 +376,8 @@ private slots:
|
|||
void slotItemCompleted(const SyncFileItemPtr &);
|
||||
|
||||
void slotRunEtagJob();
|
||||
void etagRetrieved(const QString &, const QDateTime &tp);
|
||||
void etagRetrievedFromSyncEngine(const QString &, const QDateTime &time);
|
||||
void etagRetrieved(const QByteArray &, const QDateTime &tp);
|
||||
void etagRetrievedFromSyncEngine(const QByteArray &, const QDateTime &time);
|
||||
|
||||
void slotEmitFinishedDelayed();
|
||||
|
||||
|
@ -447,7 +447,7 @@ private:
|
|||
SyncResult _syncResult;
|
||||
QScopedPointer<SyncEngine> _engine;
|
||||
QPointer<RequestEtagJob> _requestEtagJob;
|
||||
QString _lastEtag;
|
||||
QByteArray _lastEtag;
|
||||
QElapsedTimer _timeSinceLastSyncDone;
|
||||
QElapsedTimer _timeSinceLastSyncStart;
|
||||
QElapsedTimer _timeSinceLastFullLocalDiscovery;
|
||||
|
|
|
@ -545,15 +545,14 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
|
|||
item->_modtime = serverEntry.modtime;
|
||||
item->_size = serverEntry.size;
|
||||
|
||||
auto postProcessServerNew = [=] () {
|
||||
auto tmp_path = path;
|
||||
auto postProcessServerNew = [=]() mutable {
|
||||
if (item->isDirectory()) {
|
||||
_pendingAsyncJobs++;
|
||||
_discoveryData->checkSelectiveSyncNewFolder(tmp_path._server, serverEntry.remotePerm,
|
||||
_discoveryData->checkSelectiveSyncNewFolder(path._server, serverEntry.remotePerm,
|
||||
[=](bool result) {
|
||||
--_pendingAsyncJobs;
|
||||
if (!result) {
|
||||
processFileAnalyzeLocalInfo(item, tmp_path, localEntry, serverEntry, dbEntry, _queryServer);
|
||||
processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
|
||||
}
|
||||
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
|
||||
});
|
||||
|
@ -568,7 +567,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
|
|||
&& !FileSystem::isExcludeFile(item->_file)) {
|
||||
item->_type = ItemTypeVirtualFile;
|
||||
if (isVfsWithSuffix())
|
||||
addVirtualFileSuffix(tmp_path._original);
|
||||
addVirtualFileSuffix(path._original);
|
||||
}
|
||||
|
||||
if (opts._vfs->mode() != Vfs::Off && !item->_encryptedFileName.isEmpty()) {
|
||||
|
@ -579,7 +578,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
|
|||
// another scenario - we are syncing a file which is on disk but not in the database (database was removed or file was not written there yet)
|
||||
item->_size = serverEntry.size - Constants::e2EeTagSize;
|
||||
}
|
||||
processFileAnalyzeLocalInfo(item, tmp_path, localEntry, serverEntry, dbEntry, _queryServer);
|
||||
processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
|
||||
};
|
||||
|
||||
// Potential NEW/NEW conflict is handled in AnalyzeLocal
|
||||
|
@ -698,8 +697,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
|
|||
// we need to make a request to the server to know that the original file is deleted on the server
|
||||
_pendingAsyncJobs++;
|
||||
auto job = new RequestEtagJob(_discoveryData->_account, originalPath, this);
|
||||
connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QString> &etag) {
|
||||
auto tmp_path = path;
|
||||
connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QByteArray> &etag) mutable {
|
||||
_pendingAsyncJobs--;
|
||||
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
|
||||
if (etag || etag.error().code != 404 ||
|
||||
|
@ -715,8 +713,8 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
|
|||
// In case the deleted item was discovered in parallel
|
||||
_discoveryData->findAndCancelDeletedJob(originalPath);
|
||||
|
||||
postProcessRename(tmp_path);
|
||||
processFileFinalize(item, tmp_path, item->isDirectory(), item->_instruction == CSYNC_INSTRUCTION_RENAME ? NormalQuery : ParentDontExist, _queryServer);
|
||||
postProcessRename(path);
|
||||
processFileFinalize(item, path, item->isDirectory(), item->_instruction == CSYNC_INSTRUCTION_RENAME ? NormalQuery : ParentDontExist, _queryServer);
|
||||
});
|
||||
job->start();
|
||||
done = true; // Ideally, if the origin still exist on the server, we should continue searching... but that'd be difficult
|
||||
|
@ -1162,8 +1160,8 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
|
|||
if (base.isVirtualFile() && isVfsWithSuffix())
|
||||
chopVirtualFileSuffix(serverOriginalPath);
|
||||
auto job = new RequestEtagJob(_discoveryData->_account, serverOriginalPath, this);
|
||||
connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QString> &etag) mutable {
|
||||
if (!etag || (*etag != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath)) {
|
||||
connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QByteArray> &etag) mutable {
|
||||
if (!etag || (etag.get() != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath)) {
|
||||
qCInfo(lcDisco) << "Can't rename because the etag has changed or the directory is gone" << originalPath;
|
||||
// Can't be a rename, leave it as a new.
|
||||
postProcessLocalNew();
|
||||
|
@ -1171,7 +1169,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
|
|||
// In case the deleted item was discovered in parallel
|
||||
_discoveryData->findAndCancelDeletedJob(originalPath);
|
||||
processRename(path);
|
||||
recurseQueryServer = *etag == base._etag ? ParentNotChanged : NormalQuery;
|
||||
recurseQueryServer = etag.get() == base._etag ? ParentNotChanged : NormalQuery;
|
||||
}
|
||||
processFileFinalize(item, path, item->isDirectory(), NormalQuery, recurseQueryServer);
|
||||
_pendingAsyncJobs--;
|
||||
|
|
|
@ -293,6 +293,6 @@ private:
|
|||
signals:
|
||||
void finished();
|
||||
// The root etag of this directory was fetched
|
||||
void etag(const QString &, const QDateTime &time);
|
||||
void etag(const QByteArray &, const QDateTime &time);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -486,7 +486,7 @@ void DiscoverySingleDirectoryJob::directoryListingIteratedSlot(const QString &fi
|
|||
//This works in concerto with the RequestEtagJob and the Folder object to check if the remote folder changed.
|
||||
if (map.contains("getetag")) {
|
||||
if (_firstEtag.isEmpty()) {
|
||||
_firstEtag = parseEtag(map.value("getetag").toUtf8()); // for directory itself
|
||||
_firstEtag = parseEtag(map.value(QStringLiteral("getetag")).toUtf8()); // for directory itself
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public:
|
|||
// This is not actually a network job, it is just a job
|
||||
signals:
|
||||
void firstDirectoryPermissions(RemotePermissions);
|
||||
void etag(const QString &, const QDateTime &time);
|
||||
void etag(const QByteArray &, const QDateTime &time);
|
||||
void finished(const HttpResult<QVector<RemoteInfo>> &result);
|
||||
|
||||
private slots:
|
||||
|
@ -141,7 +141,7 @@ private slots:
|
|||
private:
|
||||
QVector<RemoteInfo> _results;
|
||||
QString _subPath;
|
||||
QString _firstEtag;
|
||||
QByteArray _firstEtag;
|
||||
QByteArray _fileId;
|
||||
AccountPtr _account;
|
||||
// The first result is for the directory itself and need to be ignored.
|
||||
|
|
|
@ -113,8 +113,8 @@ bool RequestEtagJob::finished()
|
|||
if (httpCode == 207) {
|
||||
// Parse DAV response
|
||||
QXmlStreamReader reader(reply());
|
||||
reader.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration("d", "DAV:"));
|
||||
QString etag;
|
||||
reader.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration(QStringLiteral("d"), QStringLiteral("DAV:")));
|
||||
QByteArray etag;
|
||||
while (!reader.atEnd()) {
|
||||
QXmlStreamReader::TokenType type = reader.readNext();
|
||||
if (type == QXmlStreamReader::StartElement && reader.namespaceUri() == QLatin1String("DAV:")) {
|
||||
|
@ -123,9 +123,9 @@ bool RequestEtagJob::finished()
|
|||
auto etagText = reader.readElementText();
|
||||
auto parsedTag = parseEtag(etagText.toUtf8());
|
||||
if (!parsedTag.isEmpty()) {
|
||||
etag += QString::fromUtf8(parsedTag);
|
||||
etag += parsedTag;
|
||||
} else {
|
||||
etag += etagText;
|
||||
etag += etagText.toUtf8();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -349,8 +349,8 @@ public:
|
|||
void start() override;
|
||||
|
||||
signals:
|
||||
void etagRetrieved(const QString &etag, const QDateTime &time);
|
||||
void finishedWithResult(const HttpResult<QString> &etag);
|
||||
void etagRetrieved(const QByteArray &etag, const QDateTime &time);
|
||||
void finishedWithResult(const HttpResult<QByteArray> &etag);
|
||||
|
||||
private slots:
|
||||
bool finished() override;
|
||||
|
|
|
@ -614,7 +614,7 @@ void SyncEngine::slotFolderDiscovered(bool local, const QString &folder)
|
|||
emit transmissionProgress(*_progressInfo);
|
||||
}
|
||||
|
||||
void SyncEngine::slotRootEtagReceived(const QString &e, const QDateTime &time)
|
||||
void SyncEngine::slotRootEtagReceived(const QByteArray &e, const QDateTime &time)
|
||||
{
|
||||
if (_remoteRootEtag.isEmpty()) {
|
||||
qCDebug(lcEngine) << "Root etag:" << e;
|
||||
|
|
|
@ -138,7 +138,7 @@ public:
|
|||
|
||||
signals:
|
||||
// During update, before reconcile
|
||||
void rootEtag(const QString &, const QDateTime &);
|
||||
void rootEtag(const QByteArray &, const QDateTime &);
|
||||
|
||||
// after the above signals. with the items that actually need propagating
|
||||
void aboutToPropagate(SyncFileItemVector &);
|
||||
|
@ -174,7 +174,7 @@ signals:
|
|||
|
||||
private slots:
|
||||
void slotFolderDiscovered(bool local, const QString &folder);
|
||||
void slotRootEtagReceived(const QString &, const QDateTime &time);
|
||||
void slotRootEtagReceived(const QByteArray &, const QDateTime &time);
|
||||
|
||||
/** When the discovery phase discovers an item */
|
||||
void slotItemDiscovered(const SyncFileItemPtr &item);
|
||||
|
@ -234,7 +234,7 @@ private:
|
|||
bool _syncRunning;
|
||||
QString _localPath;
|
||||
QString _remotePath;
|
||||
QString _remoteRootEtag;
|
||||
QByteArray _remoteRootEtag;
|
||||
SyncJournalDb *_journal;
|
||||
QScopedPointer<DiscoveryPhase> _discoveryPhase;
|
||||
QSharedPointer<OwncloudPropagator> _propagator;
|
||||
|
|
Loading…
Reference in a new issue