Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2021-02-25 16:42:23 +0300
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>2021-08-23 10:44:33 +0300
commit5b457a1663cfd6df63e6762ddc9a7d1a29200455 (patch)
tree24a563535abb444b31ab2444e6ee6ebf7975bdc7
parent5a7fd3f316d0ccd974a6e5d07ff3f47e896c5277 (diff)
Use byte array for etag
-rw-r--r--src/common/result.h7
-rw-r--r--src/gui/folder.cpp4
-rw-r--r--src/gui/folder.h6
-rw-r--r--src/libsync/discovery.cpp26
-rw-r--r--src/libsync/discovery.h2
-rw-r--r--src/libsync/discoveryphase.cpp2
-rw-r--r--src/libsync/discoveryphase.h4
-rw-r--r--src/libsync/networkjobs.cpp8
-rw-r--r--src/libsync/networkjobs.h8
-rw-r--r--src/libsync/syncengine.cpp2
-rw-r--r--src/libsync/syncengine.h6
11 files changed, 40 insertions, 35 deletions
diff --git a/src/common/result.h b/src/common/result.h
index 25129e875..77a9d121c 100644
--- a/src/common/result.h
+++ b/src/common/result.h
@@ -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);
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index cda9b0cb2..4fb5a259e 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -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);
diff --git a/src/gui/folder.h b/src/gui/folder.h
index 809ca85e7..4e0e9fa97 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -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;
diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp
index 5f0ead066..45bcf96a1 100644
--- a/src/libsync/discovery.cpp
+++ b/src/libsync/discovery.cpp
@@ -528,7 +528,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
}
return ParentNotChanged;
}();
-
+
processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, serverQueryMode);
return;
}
@@ -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--;
diff --git a/src/libsync/discovery.h b/src/libsync/discovery.h
index fd70f3139..bc1737644 100644
--- a/src/libsync/discovery.h
+++ b/src/libsync/discovery.h
@@ -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);
};
}
diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp
index 6b108e4dd..208b6e2ff 100644
--- a/src/libsync/discoveryphase.cpp
+++ b/src/libsync/discoveryphase.cpp
@@ -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
}
}
}
diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h
index 26b06e15f..945b74e79 100644
--- a/src/libsync/discoveryphase.h
+++ b/src/libsync/discoveryphase.h
@@ -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.
diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp
index adcc9bc4f..9224afc76 100644
--- a/src/libsync/networkjobs.cpp
+++ b/src/libsync/networkjobs.cpp
@@ -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();
}
}
}
diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h
index c52883b07..45fb12a22 100644
--- a/src/libsync/networkjobs.h
+++ b/src/libsync/networkjobs.h
@@ -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;
@@ -421,10 +421,10 @@ signals:
* @param statusCode - the OCS status code: 100 (!) for success
*/
void etagResponseHeaderReceived(const QByteArray &value, int statusCode);
-
+
/**
* @brief desktopNotificationStatusReceived - signal to report if notifications are allowed
- * @param status - set desktop notifications allowed status
+ * @param status - set desktop notifications allowed status
*/
void allowDesktopNotificationsChanged(bool isAllowed);
diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp
index e8cb1863d..a3307f915 100644
--- a/src/libsync/syncengine.cpp
+++ b/src/libsync/syncengine.cpp
@@ -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;
diff --git a/src/libsync/syncengine.h b/src/libsync/syncengine.h
index a9e50a197..0f5e2264e 100644
--- a/src/libsync/syncengine.h
+++ b/src/libsync/syncengine.h
@@ -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;