diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-07-14 14:05:30 +0300 |
---|---|---|
committer | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-07-14 15:33:03 +0300 |
commit | 2b9c2d6b860cd2bbeba67da4488c2eb8920a3a5d (patch) | |
tree | 2fe8c395185ff646997b9491f5c29e901695ad51 | |
parent | bb4b664202c5eb729ab91e3c4e8e0d5ca16eff7a (diff) |
Use map access instead of iterationwork/map
-rw-r--r-- | src/libsync/discoveryphase.cpp | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 0dd14653d..d75ef6033 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -387,37 +387,34 @@ void DiscoverySingleDirectoryJob::abort() static void propertyMapToRemoteInfo(const QMap<QString, QString> &map, RemoteInfo &result) { - for (auto it = map.constBegin(); it != map.constEnd(); ++it) { - QString property = it.key(); - QString value = it.value(); - if (property == QLatin1String("resourcetype")) { - result.isDirectory = value.contains(QLatin1String("collection")); - } else if (property == QLatin1String("getlastmodified")) { - const auto date = QDateTime::fromString(value, Qt::RFC2822Date); - Q_ASSERT(date.isValid()); - result.modtime = date.toTime_t(); - } else if (property == QLatin1String("getcontentlength")) { - // See #4573, sometimes negative size values are returned - bool ok = false; - qlonglong ll = value.toLongLong(&ok); - if (ok && ll >= 0) { - result.size = ll; - } else { - result.size = 0; - } - } else if (property == QLatin1String("getetag")) { - result.etag = Utility::normalizeEtag(value.toUtf8()); - } else if (property == QLatin1String("id")) { - result.fileId = value.toUtf8(); - } else if (property == QLatin1String("downloadURL")) { - result.directDownloadUrl = value; - } else if (property == QLatin1String("dDC")) { - result.directDownloadCookies = value; - } else if (property == QLatin1String("permissions")) { - result.remotePerm = RemotePermissions::fromServerString(value); - } else if (property == QLatin1String("checksums")) { - result.checksumHeader = findBestChecksum(value.toUtf8()); - } else if (property == QLatin1String("share-types") && !value.isEmpty()) { + result.isDirectory = map.value(QStringLiteral("resourcetype")).contains(QStringLiteral("collection")); + result.directDownloadUrl = map.value(QStringLiteral("downloadURL")); + result.directDownloadCookies = map.value(QStringLiteral("dDC")); + + if (auto it = Utility::optionalFind(map, QStringLiteral("getlastmodified"))) { + const auto date = QDateTime::fromString(**it, Qt::RFC2822Date); + Q_ASSERT(date.isValid()); + result.modtime = date.toTime_t(); + } + if (auto it = Utility::optionalFind(map, QStringLiteral("getcontentlength"))) { + // See #4573, sometimes negative size values are returned + result.size = std::max<int64_t>(0, it->value().toLongLong()); + } + if (auto it = Utility::optionalFind(map, QStringLiteral("getetag"))) { + result.etag = Utility::normalizeEtag(it->value().toUtf8()); + } + if (auto it = Utility::optionalFind(map, QStringLiteral("id"))) { + result.fileId = it->value().toUtf8(); + } + if (auto it = Utility::optionalFind(map, QStringLiteral("checksums"))) { + result.checksumHeader = findBestChecksum(it->value().toUtf8()); + } + if (auto it = Utility::optionalFind(map, QStringLiteral("permissions"))) { + result.remotePerm = RemotePermissions::fromServerString(it->value()); + } + if (auto it = Utility::optionalFind(map, QStringLiteral("share-types"))) { + const QString &value = it->value(); + if (!value.isEmpty()) { // Since QMap is sorted, "share-types" is always after "permissions". if (result.remotePerm.isNull()) { qWarning() << "Server returned a share type, but no permissions?"; |