diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 3e0d157628..9d1c035504 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -80,7 +80,7 @@ namespace { // item if no items are in progress. SyncFileItem curItem = progress._lastCompletedItem; qint64 curItemProgress = -1; // -1 means finished - qint64 biggerItemSize = 0; + uint64_t biggerItemSize = 0; quint64 estimatedUpBw = 0; quint64 estimatedDownBw = 0; QStringList allFilenames; @@ -135,11 +135,11 @@ namespace { pi->_progressString = fileProgressString; // overall progress - qint64 completedSize = progress.completedSize(); - qint64 completedFile = progress.completedFiles(); - qint64 currentFile = progress.currentFile(); - qint64 totalSize = qMax(completedSize, progress.totalSize()); - qint64 totalFileCount = qMax(currentFile, progress.totalFiles()); + const auto completedSize = progress.completedSize(); + const auto completedFile = progress.completedFiles(); + const auto currentFile = progress.currentFile(); + const auto totalSize = qMax(completedSize, progress.totalSize()); + const auto totalFileCount = qMax(currentFile, progress.totalFiles()); QString overallSyncString; if (totalSize > 0) { const QString s1 = Utility::octetsToString(completedSize); diff --git a/src/gui/protocolitem.cpp b/src/gui/protocolitem.cpp index ccf771fc20..1571ba3e44 100644 --- a/src/gui/protocolitem.cpp +++ b/src/gui/protocolitem.cpp @@ -56,7 +56,7 @@ QDateTime ProtocolItem::timestamp() const return _timestamp; } -qint64 ProtocolItem::size() const +uint64_t ProtocolItem::size() const { return _size; } diff --git a/src/gui/protocolitem.h b/src/gui/protocolitem.h index a216f9c756..cb46d95832 100644 --- a/src/gui/protocolitem.h +++ b/src/gui/protocolitem.h @@ -38,7 +38,7 @@ class OPENCLOUD_GUI_EXPORT ProtocolItem */ QDateTime timestamp() const; - qint64 size() const; + uint64_t size() const; SyncFileItem::Status status() const; @@ -52,12 +52,12 @@ class OPENCLOUD_GUI_EXPORT ProtocolItem QString _path; Folder *_folder; QDateTime _timestamp; - qint64 _size; - SyncFileItem::Status _status; - SyncFileItem::Direction _direction; + uint64_t _size = 0; + SyncFileItem::Status _status = {}; + SyncFileItem::Direction _direction = {}; QString _message; - bool _sizeIsRelevant; + bool _sizeIsRelevant = false; friend class TestProtocolModel; }; diff --git a/src/gui/selectivesyncwidget.cpp b/src/gui/selectivesyncwidget.cpp index 5e1d9389df..b504511d2b 100644 --- a/src/gui/selectivesyncwidget.cpp +++ b/src/gui/selectivesyncwidget.cpp @@ -159,7 +159,7 @@ static QTreeWidgetItem *findFirstChild(QTreeWidgetItem *parent, const QString &t * last item of the path/pathTrail: all parent items need to be expandable in order to reach * that last folder. So all parents of that folder will have expansion triangles shown. */ -void SelectiveSyncWidget::recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path, qint64 size, bool showChildIndicator) +void SelectiveSyncWidget::recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path, uint64_t size, bool showChildIndicator) { if (pathTrail.size() == 0) { if (path.endsWith(QLatin1Char('/'))) { @@ -253,10 +253,9 @@ void SelectiveSyncWidget::slotUpdateDirectories(QStringList list) root->setIcon(0, Theme::instance()->applicationIcon()); root->setData(0, Qt::UserRole, QString()); root->setCheckState(0, Qt::Checked); - qint64 size = job ? job->sizes().value(rootPath, -1) : -1; - if (size >= 0) { - root->setText(1, Utility::octetsToString(size)); - root->setData(1, Qt::UserRole, size); + if (const auto size = job ? Utility::optionalFind(job->sizes(), rootPath) : std::nullopt) { + root->setText(1, Utility::octetsToString(size->value())); + root->setData(1, Qt::UserRole, size->value()); } } @@ -391,39 +390,6 @@ QSet SelectiveSyncWidget::createBlackList(QTreeWidgetItem *root) const return result; } -qint64 SelectiveSyncWidget::estimatedSize(QTreeWidgetItem *root) -{ - if (!root) { - root = _folderTree->topLevelItem(0); - } - if (!root) - return -1; - - - switch (root->checkState(0)) { - case Qt::Unchecked: - return 0; - case Qt::Checked: - return root->data(1, Qt::UserRole).toLongLong(); - case Qt::PartiallyChecked: - break; - } - - qint64 result = 0; - if (root->childCount()) { - for (int i = 0; i < root->childCount(); ++i) { - auto r = estimatedSize(root->child(i)); - if (r < 0) - return r; - result += r; - } - } else { - // We did not load from the server so we have no idea how much we will sync from this branch - return -1; - } - return result; -} - void SelectiveSyncWidget::setDavUrl(const QUrl &davUrl) { _davUrl = davUrl; diff --git a/src/gui/selectivesyncwidget.h b/src/gui/selectivesyncwidget.h index 82759d98a3..77087773fa 100644 --- a/src/gui/selectivesyncwidget.h +++ b/src/gui/selectivesyncwidget.h @@ -14,7 +14,6 @@ #pragma once #include "accountfwd.h" -#include #include #include @@ -41,9 +40,6 @@ class SelectiveSyncWidget : public QWidget /// Returns a list of blacklisted paths, each including the trailing / QSet createBlackList(QTreeWidgetItem *root = nullptr) const; - // Estimates the total size of checked items (recursively) - qint64 estimatedSize(QTreeWidgetItem *root = nullptr); - // oldBlackList is a list of excluded paths, each including a trailing / void setFolderInfo(const QString &rootName, const QSet &oldBlackList = {}); @@ -58,7 +54,7 @@ private Q_SLOTS: private: void refreshFolders(); - void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path, qint64 size, bool showChildIndicator); + void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path, uint64_t size, bool showChildIndicator); QUrl davUrl() const; private: diff --git a/src/gui/syncrunfilelog.cpp b/src/gui/syncrunfilelog.cpp index ca56985dc6..5d2d68d428 100644 --- a/src/gui/syncrunfilelog.cpp +++ b/src/gui/syncrunfilelog.cpp @@ -19,6 +19,8 @@ #include "filesystem.h" #include +using namespace OCC::FileSystem::SizeLiterals; + namespace { auto dateTimeStr(const QDateTime &dt = QDateTime::currentDateTimeUtc()) { @@ -35,7 +37,7 @@ SyncRunFileLog::SyncRunFileLog() void SyncRunFileLog::start(const QString &folderPath) { - const qint64 logfileMaxSize = 10 * 1024 * 1024; // 10MiB + const auto logfileMaxSize = 10_MiB; // 10MiB // Note; this name is ignored in csync_exclude.c const QString filename = folderPath + QStringLiteral(".OpenCloudSync.log"); diff --git a/src/libsync/common/checksums.cpp b/src/libsync/common/checksums.cpp index 13d8304019..d4660cf622 100644 --- a/src/libsync/common/checksums.cpp +++ b/src/libsync/common/checksums.cpp @@ -90,7 +90,7 @@ namespace { QByteArray calcAdler32(QIODevice *device) { - const qint64 BUFSIZE(500 * 1024); // 500 KiB + const uint64_t BUFSIZE(500 * 1024); // 500 KiB if (device->size() == 0) { return QByteArray(); } diff --git a/src/libsync/common/filesystembase.cpp b/src/libsync/common/filesystembase.cpp index a74f7e4d09..ca2ad850d0 100644 --- a/src/libsync/common/filesystembase.cpp +++ b/src/libsync/common/filesystembase.cpp @@ -269,7 +269,7 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName, const QSt return true; } -bool FileSystem::openAndSeekFileSharedRead(QFile *file, QString *errorOrNull, qint64 seek) +bool FileSystem::openAndSeekFileSharedRead(QFile *file, QString *errorOrNull, uint64_t seek) { QString errorDummy; // avoid many if (errorOrNull) later. diff --git a/src/libsync/common/filesystembase.h b/src/libsync/common/filesystembase.h index 5c48bae8c4..ca62bd054c 100644 --- a/src/libsync/common/filesystembase.h +++ b/src/libsync/common/filesystembase.h @@ -136,7 +136,7 @@ OPENCLOUD_SYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcFileSystem) * Warning: The resulting file may have an empty fileName and be unsuitable for use * with QFileInfo! Calling seek() on the QFile with >32bit signed values will fail! */ - bool OPENCLOUD_SYNC_EXPORT openAndSeekFileSharedRead(QFile * file, QString * error, qint64 seek); + bool OPENCLOUD_SYNC_EXPORT openAndSeekFileSharedRead(QFile * file, QString * error, uint64_t seek); enum class LockMode { Shared, Exclusive, SharedRead }; Q_ENUM_NS(LockMode); diff --git a/src/libsync/common/ownsql.cpp b/src/libsync/common/ownsql.cpp index 70892765ed..5ef9d745c7 100644 --- a/src/libsync/common/ownsql.cpp +++ b/src/libsync/common/ownsql.cpp @@ -152,8 +152,8 @@ bool SqlDatabase::openOrCreateReadWrite(const QString &filename) if (checkResult == CheckDbResult::CantPrepare) { // When disk space is low, preparing may fail even though the db is fine. // Typically CANTOPEN or IOERR. - qint64 freeSpace = Utility::freeDiskSpace(QFileInfo(filename).dir().absolutePath()); - if (freeSpace != -1 && freeSpace < 1000000) { + auto freeSpace = Utility::freeDiskSpace(QFileInfo(filename).dir().absolutePath()); + if (freeSpace && freeSpace < 1000000) { qCWarning(lcSql) << u"Can't prepare consistency check and disk space is low:" << freeSpace; } else if (_errId == SQLITE_CANTOPEN) { // Even when there's enough disk space, it might very well be that the diff --git a/src/libsync/common/syncjournaldb.cpp b/src/libsync/common/syncjournaldb.cpp index 31c1350d53..5666ea1f27 100644 --- a/src/libsync/common/syncjournaldb.cpp +++ b/src/libsync/common/syncjournaldb.cpp @@ -1170,6 +1170,13 @@ static bool deleteBatch(SqlQuery &query, const QStringList &entries, const QStri return true; } +bool SyncJournalDb::UploadInfo::validate(uint64_t size, qint64 modtime, const QByteArray &checksum) const +{ + Q_ASSERT(!checksum.isEmpty()); + Q_ASSERT(!_valid || !_contentChecksum.isEmpty()); + return _valid && _size == size && _modtime == modtime && _contentChecksum == checksum; +} + SyncJournalDb::DownloadInfo SyncJournalDb::getDownloadInfo(const QString &file) { QMutexLocker locker(&_mutex); diff --git a/src/libsync/common/syncjournaldb.h b/src/libsync/common/syncjournaldb.h index fa8bf6c46c..d41ee1fcf5 100644 --- a/src/libsync/common/syncjournaldb.h +++ b/src/libsync/common/syncjournaldb.h @@ -106,18 +106,13 @@ class OPENCLOUD_SYNC_EXPORT SyncJournalDb : public QObject { bool _valid = false; - qint64 _size = 0; + uint64_t _size = 0; qint64 _modtime = 0; QByteArray _contentChecksum; QUrl _url; // upload url (tus) QString _path; // stored as utf16, used in local discovery - bool validate(qint64 size, qint64 modtime, const QByteArray &checksum) const - { - Q_ASSERT(!checksum.isEmpty()); - Q_ASSERT(!_valid || !_contentChecksum.isEmpty()); - return _valid && _size == size && _modtime == modtime && _contentChecksum == checksum; - } + bool validate(uint64_t size, qint64 modtime, const QByteArray &checksum) const; }; DownloadInfo getDownloadInfo(const QString &file); diff --git a/src/libsync/common/syncjournalfilerecord.cpp b/src/libsync/common/syncjournalfilerecord.cpp index 88739f22d2..e375381741 100644 --- a/src/libsync/common/syncjournalfilerecord.cpp +++ b/src/libsync/common/syncjournalfilerecord.cpp @@ -40,7 +40,7 @@ class OCC::SyncJournalFileRecordData : public QSharedData ItemType _type = ItemTypeUnsupported; QString _etag; QByteArray _fileId; - qint64 _fileSize = 0; + uint64_t _fileSize = 0; RemotePermissions _remotePerm; bool _serverHasIgnoredFiles = false; bool _hasDirtyPlaceholder = false; @@ -195,7 +195,7 @@ time_t SyncJournalFileRecord::modtime() const return d->_modtime.value_or(0); } -int64_t SyncJournalFileRecord::size() const +uint64_t SyncJournalFileRecord::size() const { return d->_fileSize; } diff --git a/src/libsync/common/syncjournalfilerecord.h b/src/libsync/common/syncjournalfilerecord.h index 5ed83d752e..a614448fd8 100644 --- a/src/libsync/common/syncjournalfilerecord.h +++ b/src/libsync/common/syncjournalfilerecord.h @@ -63,7 +63,7 @@ class OPENCLOUD_SYNC_EXPORT SyncJournalFileRecord RemotePermissions remotePerm() const; QByteArray checksumHeader() const; time_t modtime() const; - int64_t size() const; + uint64_t size() const; uint64_t inode() const; ItemType type() const; diff --git a/src/libsync/common/utility.cpp b/src/libsync/common/utility.cpp index 8efbe984ad..7c079752c0 100644 --- a/src/libsync/common/utility.cpp +++ b/src/libsync/common/utility.cpp @@ -65,18 +65,16 @@ namespace OCC { Q_LOGGING_CATEGORY(lcUtility, "sync.utility", QtMsgType::QtInfoMsg) -QString Utility::octetsToString(qint64 octets) +QString Utility::octetsToString(uint64_t octets) { - OC_ASSERT(octets >= 0) - using namespace FileSystem::SizeLiterals; // We do what macOS 10.8 and above do: 0 fraction digits for bytes and KB; 1 fraction digits for MB; 2 for GB and above. // See also https://developer.apple.com/documentation/foundation/nsbytecountformatter/1417887-adaptive int precision = 0; - if (quint64(octets) >= 1_GiB) { + if (octets >= 1_GiB) { precision = 2; - } else if (quint64(octets) >= 1_MiB) { + } else if (octets >= 1_MiB) { precision = 1; } @@ -116,26 +114,25 @@ QByteArray Utility::userAgentString() .toLatin1(); } -qint64 Utility::freeDiskSpace(const QString &path) +std::optional Utility::freeDiskSpace(const QString &path) { #if defined(Q_OS_MAC) || defined(Q_OS_FREEBSD) || defined(Q_OS_FREEBSD_KERNEL) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) struct statvfs stat; if (statvfs(path.toLocal8Bit().data(), &stat) == 0) { - return (qint64)stat.f_bavail * stat.f_frsize; + return stat.f_bavail * stat.f_frsize; } #elif defined(Q_OS_UNIX) struct statvfs64 stat; if (statvfs64(path.toLocal8Bit().data(), &stat) == 0) { - return (qint64)stat.f_bavail * stat.f_frsize; + return stat.f_bavail * stat.f_frsize; } #elif defined(Q_OS_WIN) - ULARGE_INTEGER freeBytes; - freeBytes.QuadPart = 0L; + ULARGE_INTEGER freeBytes = {}; if (GetDiskFreeSpaceEx(reinterpret_cast(FileSystem::longWinPath(path).utf16()), &freeBytes, nullptr, nullptr)) { return freeBytes.QuadPart; } #endif - return -1; + return {}; } QString Utility::compactFormatDouble(double value, int prec, const QString &unit) diff --git a/src/libsync/common/utility.h b/src/libsync/common/utility.h index 83bbf144d0..b01df62d5e 100644 --- a/src/libsync/common/utility.h +++ b/src/libsync/common/utility.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -50,7 +49,7 @@ OPENCLOUD_SYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcUtility) namespace Utility { OPENCLOUD_SYNC_EXPORT void setupFavLink(const QString &folder); - OPENCLOUD_SYNC_EXPORT QString octetsToString(qint64 octets); + OPENCLOUD_SYNC_EXPORT QString octetsToString(uint64_t octets); OPENCLOUD_SYNC_EXPORT QByteArray userAgentString(); /** @@ -75,7 +74,7 @@ OPENCLOUD_SYNC_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcUtility) * * \a path must point to a directory */ - OPENCLOUD_SYNC_EXPORT qint64 freeDiskSpace(const QString &path); + OPENCLOUD_SYNC_EXPORT std::optional freeDiskSpace(const QString &path); /** * @brief compactFormatDouble - formats a double value human readable. diff --git a/src/libsync/discoveryinfo.cpp b/src/libsync/discoveryinfo.cpp index 59639e7831..a8ac907758 100644 --- a/src/libsync/discoveryinfo.cpp +++ b/src/libsync/discoveryinfo.cpp @@ -54,6 +54,7 @@ class OCC::LocalInfoData : public QSharedData return; } _inode = sb.st_ino; + Q_ASSERT(sb.st_size >= 0); _size = sb.st_size; _modtime = sb.st_mtime; #ifdef Q_OS_MAC @@ -65,7 +66,7 @@ class OCC::LocalInfoData : public QSharedData QString _name; ItemType _type = ItemTypeUnsupported; time_t _modtime = 0; - int64_t _size = 0; + uint64_t _size = 0; uint64_t _inode = 0; bool _isHidden = false; }; @@ -129,7 +130,7 @@ time_t LocalInfo::modtime() const return d->_modtime; } -int64_t LocalInfo::size() const +uint64_t LocalInfo::size() const { return d->_size; } diff --git a/src/libsync/discoveryinfo.h b/src/libsync/discoveryinfo.h index ef64817f18..4974fd5295 100644 --- a/src/libsync/discoveryinfo.h +++ b/src/libsync/discoveryinfo.h @@ -36,7 +36,7 @@ class OPENCLOUD_SYNC_EXPORT LocalInfo /** FileName of the entry (this does not contain any directory or path, just the plain name */ QString name() const; time_t modtime() const; - int64_t size() const; + uint64_t size() const; uint64_t inode() const; ItemType type() const; bool isDirectory() const; diff --git a/src/libsync/discoveryremoteinfo.cpp b/src/libsync/discoveryremoteinfo.cpp index ad559f6c9c..c58d60e036 100644 --- a/src/libsync/discoveryremoteinfo.cpp +++ b/src/libsync/discoveryremoteinfo.cpp @@ -31,8 +31,7 @@ class OCC::RemoteInfoData : public QSharedData _size = 0; } else { if (auto it = Utility::optionalFind(map, "getcontentlength"_L1)) { - // See #4573, sometimes negative size values are returned - _size = std::max(0, it->value().toLongLong()); + _size = it->value().toULongLong(); } else { errors.append(u"size"_s); } @@ -74,7 +73,7 @@ class OCC::RemoteInfoData : public QSharedData QByteArray _checksumHeader; RemotePermissions _remotePerm; time_t _modtime = 0; - int64_t _size = 0; + uint64_t _size = 0; bool _isDirectory = false; QString _error; @@ -134,7 +133,7 @@ time_t RemoteInfo::modtime() const return d->_modtime; } -int64_t RemoteInfo::size() const +uint64_t RemoteInfo::size() const { return d->_size; } diff --git a/src/libsync/discoveryremoteinfo.h b/src/libsync/discoveryremoteinfo.h index c495759513..01466619ee 100644 --- a/src/libsync/discoveryremoteinfo.h +++ b/src/libsync/discoveryremoteinfo.h @@ -37,7 +37,7 @@ class OPENCLOUD_SYNC_EXPORT RemoteInfo RemotePermissions remotePerm() const; time_t modtime() const; - int64_t size() const; + uint64_t size() const; QString error() const; diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index e27854a314..01653d3a0e 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -179,10 +179,10 @@ bool FileSystem::fileChanged(const std::filesystem::path &path, const FileChange return false; } -qint64 FileSystem::getSize(const std::filesystem::path &filename) +uint64_t FileSystem::getSize(const std::filesystem::path &filename) { std::error_code ec; - const quint64 size = std::filesystem::file_size(filename, ec); + const auto size = std::filesystem::file_size(filename, ec); if (ec) { if (!std::filesystem::is_directory(filename)) { qCCritical(lcFileSystem) << u"Error getting size for" << filename << ec.value() << ec.message(); diff --git a/src/libsync/filesystem.h b/src/libsync/filesystem.h index c45497d801..69a923c56c 100644 --- a/src/libsync/filesystem.h +++ b/src/libsync/filesystem.h @@ -69,8 +69,8 @@ namespace FileSystem { * Use this over QFileInfo::size() to avoid bugs with lnk files on Windows. * See https://bugreports.qt.io/browse/QTBUG-24831. */ - qint64 OPENCLOUD_SYNC_EXPORT getSize(const std::filesystem::path &filename); - inline qint64 getSize(const QFileInfo &info) + uint64_t OPENCLOUD_SYNC_EXPORT getSize(const std::filesystem::path &filename); + inline auto getSize(const QFileInfo &info) { return getSize(toFilesystemPath(info.absoluteFilePath())); } @@ -98,7 +98,7 @@ namespace FileSystem { static OPENCLOUD_SYNC_EXPORT FileChangedInfo fromSyncFileItemPrevious(const SyncFileItem *const item); static OPENCLOUD_SYNC_EXPORT FileChangedInfo fromSyncJournalFileRecord(const SyncJournalFileRecord &record); - qint64 size = {}; + uint64_t size = {}; std::optional mtime = {}; std::optional inode = {}; CSyncEnums::ItemType type = CSyncEnums::ItemTypeUnsupported; diff --git a/src/libsync/httplogger.cpp b/src/libsync/httplogger.cpp index 35da940c84..60b620a751 100644 --- a/src/libsync/httplogger.cpp +++ b/src/libsync/httplogger.cpp @@ -32,7 +32,7 @@ using namespace Qt::Literals::StringLiterals; namespace { Q_LOGGING_CATEGORY(lcNetworkHttp, "sync.httplogger", QtWarningMsg) -const qint64 PeekSize = 1024 * 1024; +const uint64_t PeekSize = 1024 * 1024; bool isTextBody(const QString &s) { diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index 716d6824a9..2bdeb86b25 100644 --- a/src/libsync/networkjobs.cpp +++ b/src/libsync/networkjobs.cpp @@ -107,7 +107,7 @@ LsColXMLParser::LsColXMLParser() { } -bool LsColXMLParser::parse(const QByteArray &xml, QHash *sizes, const QString &expectedPath) +bool LsColXMLParser::parse(const QByteArray &xml, QHash *sizes, const QString &expectedPath) { // Parse DAV response QXmlStreamReader reader(xml); @@ -162,7 +162,7 @@ bool LsColXMLParser::parse(const QByteArray &xml, QHash *sizes, folders.append(currentHref); } else if (name == QLatin1String("size")) { bool ok = false; - auto s = propertyContent.toLongLong(&ok); + auto s = propertyContent.toULongLong(&ok); if (ok && sizes) { sizes->insert(currentHref, s); } @@ -308,7 +308,7 @@ void PropfindJob::finished() } } -const QHash &PropfindJob::sizes() const +const QHash &PropfindJob::sizes() const { return _sizes; } diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h index a4464c64eb..3b3fe41ae7 100644 --- a/src/libsync/networkjobs.h +++ b/src/libsync/networkjobs.h @@ -63,7 +63,7 @@ class OPENCLOUD_SYNC_EXPORT LsColXMLParser : public QObject public: explicit LsColXMLParser(); - bool parse(const QByteArray &xml, QHash *sizes, const QString &expectedPath); + bool parse(const QByteArray &xml, QHash *sizes, const QString &expectedPath); Q_SIGNALS: void directoryListingSubfolders(const QStringList &items); @@ -94,7 +94,7 @@ class OPENCLOUD_SYNC_EXPORT PropfindJob : public AbstractNetworkJob QList properties() const; // TODO: document... - const QHash &sizes() const; + const QHash &sizes() const; Q_SIGNALS: void directoryListingSubfolders(const QStringList &items); @@ -107,7 +107,7 @@ private Q_SLOTS: private: QList _properties; - QHash _sizes; + QHash _sizes; Depth _depth; }; diff --git a/src/libsync/networkjobs/getfilejob.cpp b/src/libsync/networkjobs/getfilejob.cpp index 9b51eca51c..437c70fa45 100644 --- a/src/libsync/networkjobs/getfilejob.cpp +++ b/src/libsync/networkjobs/getfilejob.cpp @@ -12,13 +12,11 @@ Q_LOGGING_CATEGORY(lcGetJob, "sync.networkjob.get", QtInfoMsg) // DOES NOT take ownership of the device. GETFileJob::GETFileJob(AccountPtr account, const QUrl &url, const QString &path, QIODevice *device, const QMap &headers, - const QString &expectedEtagForResume, qint64 resumeStart, QObject *parent) + const QString &expectedEtagForResume, uint64_t resumeStart, QObject *parent) : AbstractNetworkJob(account, url, path, parent) , _device(device) , _headers(headers) , _expectedEtagForResume(expectedEtagForResume) - , _expectedContentLength(-1) - , _contentLength(-1) , _resumeStart(resumeStart) { connect(this, &GETFileJob::networkError, this, [this] { @@ -83,6 +81,26 @@ void GETFileJob::newReplyHook(QNetworkReply *reply) connect(reply, &QNetworkReply::downloadProgress, this, &GETFileJob::downloadProgress); } +uint64_t GETFileJob::resumeStart() const +{ + return _resumeStart; +} + +std::optional GETFileJob::contentLength() const +{ + return _contentLength; +} + +std::optional GETFileJob::expectedContentLength() const +{ + return _expectedContentLength; +} + +void GETFileJob::setExpectedContentLength(uint64_t size) +{ + _expectedContentLength = size; +} + void GETFileJob::slotMetaDataChanged() { // For some reason setting the read buffer in GETFileJob::start doesn't seem to go @@ -132,8 +150,10 @@ void GETFileJob::slotMetaDataChanged() } bool ok; - _contentLength = reply()->header(QNetworkRequest::ContentLengthHeader).toLongLong(&ok); - if (ok && _expectedContentLength != -1 && _contentLength != _expectedContentLength) { + _contentLength = reply()->header(QNetworkRequest::ContentLengthHeader).toULongLong(&ok); + if (!ok) { + _contentLength.reset(); + } else if (_expectedContentLength.has_value() && _contentLength != _expectedContentLength) { qCWarning(lcGetJob) << u"We received a different content length than expected!" << _expectedContentLength << u"vs" << _contentLength; _errorString = tr("We received an unexpected download Content-Length."); _errorStatus = SyncFileItem::NormalError; @@ -141,13 +161,13 @@ void GETFileJob::slotMetaDataChanged() return; } - qint64 start = 0; + uint64_t start = 0; const QString ranges = QString::fromUtf8(reply()->rawHeader("Content-Range")); if (!ranges.isEmpty()) { static QRegularExpression rx(QStringLiteral("bytes (\\d+)-")); const auto match = rx.match(ranges); if (match.hasMatch()) { - start = match.captured(1).toLongLong(); + start = match.captured(1).toULongLong(); } } if (start != _resumeStart) { @@ -206,9 +226,9 @@ void GETFileJob::giveBandwidthQuota(qint64 q) QMetaObject::invokeMethod(this, &GETFileJob::slotReadyRead, Qt::QueuedConnection); } -qint64 GETFileJob::currentDownloadPosition() +uint64_t GETFileJob::currentDownloadPosition() { - if (_device && _device->pos() > 0 && _device->pos() > qint64(_resumeStart)) { + if (_device && _device->pos() > 0 && static_cast(_device->pos()) > _resumeStart) { return _device->pos(); } return _resumeStart; @@ -221,7 +241,7 @@ void GETFileJob::slotReadyRead() return; } - const qint64 bufferSize = std::min(1024 * 8, reply()->bytesAvailable()); + const uint64_t bufferSize = std::min(1024 * 8, reply()->bytesAvailable()); QByteArray buffer(bufferSize, Qt::Uninitialized); while (reply()->bytesAvailable() > 0) { @@ -229,9 +249,9 @@ void GETFileJob::slotReadyRead() qCWarning(lcGetJob) << u"Download choked"; break; } - qint64 toRead = bufferSize; + uint64_t toRead = bufferSize; if (_bandwidthLimited) { - toRead = std::min(bufferSize, _bandwidthQuota); + toRead = std::min(bufferSize, _bandwidthQuota); if (toRead == 0) { qCWarning(lcGetJob) << u"Out of bandwidth quota"; break; diff --git a/src/libsync/networkjobs/getfilejob.h b/src/libsync/networkjobs/getfilejob.h index a076712a1c..834fb34964 100644 --- a/src/libsync/networkjobs/getfilejob.h +++ b/src/libsync/networkjobs/getfilejob.h @@ -21,29 +21,29 @@ class OPENCLOUD_SYNC_EXPORT GETFileJob : public AbstractNetworkJob QIODevice *_device; QMap _headers; QString _expectedEtagForResume; - qint64 _expectedContentLength; - qint64 _contentLength; - qint64 _resumeStart; + std::optional _expectedContentLength; + std::optional _contentLength; + uint64_t _resumeStart; public: // DOES NOT take ownership of the device. // For directDownloadUrl: explicit GETFileJob(AccountPtr account, const QUrl &url, const QString &path, QIODevice *device, const QMap &headers, - const QString &expectedEtagForResume, qint64 resumeStart, QObject *parent = nullptr); + const QString &expectedEtagForResume, uint64_t resumeStart, QObject *parent = nullptr); virtual ~GETFileJob(); - qint64 currentDownloadPosition(); + uint64_t currentDownloadPosition(); void start() override; void finished() override; void newReplyHook(QNetworkReply *reply) override; - qint64 resumeStart() { return _resumeStart; } + uint64_t resumeStart() const; - qint64 contentLength() const { return _contentLength; } - qint64 expectedContentLength() const { return _expectedContentLength; } - void setExpectedContentLength(qint64 size) { _expectedContentLength = size; } + std::optional contentLength() const; + std::optional expectedContentLength() const; + void setExpectedContentLength(uint64_t size); void setChoked(bool c); void setBandwidthLimited(bool b); @@ -63,7 +63,7 @@ private Q_SLOTS: void slotMetaDataChanged(); Q_SIGNALS: - void downloadProgress(qint64, qint64); + void downloadProgress(int64_t, int64_t); protected: bool restartDevice(); diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index 0c51ad5441..9fda9b2301 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -21,6 +21,7 @@ #include "common/utility.h" #include "discoveryphase.h" #include "filesystem.h" +#include "libsync/common/filesystembase.h" #include "propagatedownload.h" #include "propagateremotedelete.h" #include "propagateremotemkdir.h" @@ -42,6 +43,7 @@ #include using namespace std::chrono_literals; +using namespace OCC::FileSystem::SizeLiterals; namespace OCC { @@ -54,12 +56,12 @@ namespace { std::chrono::seconds getMaxBlacklistTime = 24h; } -qint64 criticalFreeSpaceLimit() +uint64_t criticalFreeSpaceLimit() { - return qBound(0LL, 50 * 1000 * 1000LL, freeSpaceLimit()); + return 50 * 1000 * 1000LL; } -qint64 freeSpaceLimit() +uint64_t freeSpaceLimit() { return 250 * 1000 * 1000LL; } @@ -355,10 +357,9 @@ PropagateItemJob *OwncloudPropagator::createJob(const SyncFileItemPtr &item) Q_UNREACHABLE(); } -qint64 OwncloudPropagator::smallFileSize() +uint64_t OwncloudPropagator::smallFileSize() { - const qint64 smallFileSize = 100 * 1024; //default to 1 MB. Not dynamic right now. - return smallFileSize; + return 1_MB; // default to 1 MB. Not dynamic right now. } /** @@ -656,7 +657,7 @@ void OwncloudPropagator::scheduleNextJobImpl() } } -void OwncloudPropagator::reportFileTotal(const SyncFileItem &item, qint64 newSize) +void OwncloudPropagator::reportFileTotal(const SyncFileItem &item, uint64_t newSize) { Q_EMIT updateFileTotal(item, newSize); } @@ -684,7 +685,7 @@ void OwncloudPropagator::abort() } } -void OwncloudPropagator::reportProgress(const SyncFileItem &item, qint64 bytes) +void OwncloudPropagator::reportProgress(const SyncFileItem &item, uint64_t bytes) { Q_EMIT progress(item, bytes); } @@ -696,8 +697,9 @@ AccountPtr OwncloudPropagator::account() const OwncloudPropagator::DiskSpaceResult OwncloudPropagator::diskSpaceCheck() const { - const qint64 freeBytes = Utility::freeDiskSpace(_localDir); - if (freeBytes < 0) { + const auto freeBytes = Utility::freeDiskSpace(_localDir); + if (!freeBytes.has_value()) { + // assume we are still ok return DiskSpaceOk; } @@ -705,7 +707,7 @@ OwncloudPropagator::DiskSpaceResult OwncloudPropagator::diskSpaceCheck() const return DiskSpaceCritical; } - if (freeBytes - _rootJob->committedDiskSpace() < freeSpaceLimit()) { + if (freeBytes.value() - _rootJob->committedDiskSpace() < freeSpaceLimit()) { return DiskSpaceFailure; } @@ -982,9 +984,9 @@ void PropagatorCompositeJob::finalize() Q_EMIT finished(_errorPaths.empty() ? SyncFileItem::Success : _errorPaths.last()); } -qint64 PropagatorCompositeJob::committedDiskSpace() const +uint64_t PropagatorCompositeJob::committedDiskSpace() const { - qint64 needed = 0; + uint64_t needed = 0; for (auto *job : _runningJobs) { needed += job->committedDiskSpace(); } @@ -1176,7 +1178,7 @@ void PropagateRootDirectory::abort(PropagatorJob::AbortType abortType) _dirDeletionJobs.abort(abortType); } -qint64 PropagateRootDirectory::committedDiskSpace() const +uint64_t PropagateRootDirectory::committedDiskSpace() const { return _subJobs.committedDiskSpace() + _dirDeletionJobs.committedDiskSpace(); } diff --git a/src/libsync/owncloudpropagator.h b/src/libsync/owncloudpropagator.h index a21afbfa5c..9397dac964 100644 --- a/src/libsync/owncloudpropagator.h +++ b/src/libsync/owncloudpropagator.h @@ -14,15 +14,6 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include - #include "accountfwd.h" #include "bandwidthmanager.h" #include "common/syncjournaldb.h" @@ -36,14 +27,14 @@ Q_DECLARE_LOGGING_CATEGORY(lcPropagator) /** Free disk space threshold below which syncs will abort and not even start. */ -qint64 criticalFreeSpaceLimit(); +uint64_t criticalFreeSpaceLimit(); /** The client will not intentionally reduce the available free disk space below * this limit. * * Uploads will still run and downloads that are small enough will continue too. */ -qint64 freeSpaceLimit(); +uint64_t freeSpaceLimit(); class SyncJournalDb; class OwncloudPropagator; @@ -104,7 +95,7 @@ class PropagatorJob : public QObject * Note that this does *not* include the disk space that's already * in use by running jobs for things like a download-in-progress. */ - virtual qint64 committedDiskSpace() const { return 0; } + virtual uint64_t committedDiskSpace() const { return 0; } /** Set the associated composite job * @@ -231,7 +222,7 @@ class PropagatorCompositeJob : public PropagatorJob } } - qint64 committedDiskSpace() const override; + uint64_t committedDiskSpace() const override; QMap errorPaths() const { return _errorPaths; } @@ -304,10 +295,7 @@ class OPENCLOUD_SYNC_EXPORT PropagateDirectory : public PropagateItemJob _firstJob->_item->_affectedItems++; } - qint64 committedDiskSpace() const override - { - return _subJobs.committedDiskSpace(); - } + uint64_t committedDiskSpace() const override { return _subJobs.committedDiskSpace(); } SyncFileItemPtr &item() { @@ -337,7 +325,7 @@ class OPENCLOUD_SYNC_EXPORT PropagateRootDirectory : public PropagateDirectory JobParallelism parallelism() override; void abort(PropagatorJob::AbortType abortType) override; - qint64 committedDiskSpace() const override; + uint64_t committedDiskSpace() const override; void addDeleteJob(PropagatorJob *job); @@ -431,7 +419,7 @@ class OPENCLOUD_SYNC_EXPORT OwncloudPropagator : public QObject * * This allows skipping of uploads that have a very high likelihood of failure. */ - QHash _folderQuota; + QHash _folderQuota; /* the maximum number of jobs using bandwidth (uploads or downloads, in parallel) */ int maximumActiveTransferJob(); @@ -442,8 +430,8 @@ class OPENCLOUD_SYNC_EXPORT OwncloudPropagator : public QObject * if Capabilities::desiredChunkUploadDuration has a target * chunk-upload duration set. */ - qint64 _chunkSize; - qint64 smallFileSize(); + uint64_t _chunkSize; + uint64_t smallFileSize(); /* The maximum number of active jobs in parallel */ int hardMaximumActiveJob(); @@ -480,8 +468,8 @@ class OPENCLOUD_SYNC_EXPORT OwncloudPropagator : public QObject PropagateItemJob *createJob(const SyncFileItemPtr &item); void scheduleNextJob(); - void reportProgress(const SyncFileItem &, qint64 bytes); - void reportFileTotal(const SyncFileItem &item, qint64 newSize); + void reportProgress(const SyncFileItem &, uint64_t bytes); + void reportFileTotal(const SyncFileItem &item, uint64_t newSize); void abort(); @@ -558,8 +546,8 @@ private Q_SLOTS: Q_SIGNALS: void newItem(const SyncFileItemPtr &); void itemCompleted(const SyncFileItemPtr &); - void progress(const SyncFileItem &, qint64 bytes); - void updateFileTotal(const SyncFileItem &, qint64 newSize); + void progress(const SyncFileItem &, uint64_t bytes); + void updateFileTotal(const SyncFileItem &, uint64_t newSize); void finished(bool success); /** Emitted when propagation has problems with a locked file. */ diff --git a/src/libsync/progressdispatcher.cpp b/src/libsync/progressdispatcher.cpp index 0d9ba8c75c..4936c19e10 100644 --- a/src/libsync/progressdispatcher.cpp +++ b/src/libsync/progressdispatcher.cpp @@ -179,7 +179,7 @@ void ProgressInfo::adjustTotalsForFile(const SyncFileItem &item) } } -void ProgressInfo::updateTotalsForFile(const SyncFileItem &item, qint64 newSize) +void ProgressInfo::updateTotalsForFile(const SyncFileItem &item, uint64_t newSize) { if (!shouldCountProgress(item)) { return; @@ -195,27 +195,27 @@ void ProgressInfo::updateTotalsForFile(const SyncFileItem &item, qint64 newSize) _currentItems[item.localName()]._progress._total = newSize; } -qint64 ProgressInfo::totalFiles() const +uint64_t ProgressInfo::totalFiles() const { return _fileProgress._total; } -qint64 ProgressInfo::completedFiles() const +uint64_t ProgressInfo::completedFiles() const { return _fileProgress._completed; } -qint64 ProgressInfo::currentFile() const +uint64_t ProgressInfo::currentFile() const { return completedFiles() + _currentItems.size(); } -qint64 ProgressInfo::totalSize() const +uint64_t ProgressInfo::totalSize() const { return _sizeProgress._total; } -qint64 ProgressInfo::completedSize() const +uint64_t ProgressInfo::completedSize() const { return _sizeProgress._completed; } @@ -235,7 +235,7 @@ void ProgressInfo::setProgressComplete(const SyncFileItem &item) _lastCompletedItem = item; } -void ProgressInfo::setProgressItem(const SyncFileItem &item, qint64 completed) +void ProgressInfo::setProgressItem(const SyncFileItem &item, uint64_t completed) { if (!shouldCountProgress(item)) { return; @@ -372,12 +372,12 @@ ProgressInfo::Estimates ProgressInfo::Progress::estimates() const return est; } -qint64 ProgressInfo::Progress::completed() const +uint64_t ProgressInfo::Progress::completed() const { return _completed; } -qint64 ProgressInfo::Progress::remaining() const +uint64_t ProgressInfo::Progress::remaining() const { return _total - _completed; } @@ -398,7 +398,7 @@ void ProgressInfo::Progress::update() _prevCompleted = _completed; } -void ProgressInfo::Progress::setCompleted(qint64 completed) +void ProgressInfo::Progress::setCompleted(uint64_t completed) { _completed = qMin(completed, _total); _prevCompleted = qMin(_prevCompleted, _completed); diff --git a/src/libsync/progressdispatcher.h b/src/libsync/progressdispatcher.h index a594cd670a..f4ea3f51e3 100644 --- a/src/libsync/progressdispatcher.h +++ b/src/libsync/progressdispatcher.h @@ -99,16 +99,16 @@ class OPENCLOUD_SYNC_EXPORT ProgressInfo : public QObject * adjustTotalsForFile() while newSize is the newly determined actual * size. */ - void updateTotalsForFile(const SyncFileItem &item, qint64 newSize); + void updateTotalsForFile(const SyncFileItem &item, uint64_t newSize); - qint64 totalFiles() const; - qint64 completedFiles() const; + uint64_t totalFiles() const; + uint64_t completedFiles() const; - qint64 totalSize() const; - qint64 completedSize() const; + uint64_t totalSize() const; + uint64_t completedSize() const; /** Number of a file that is currently in progress. */ - qint64 currentFile() const; + uint64_t currentFile() const; /** Return true if the size needs to be taken in account in the total amount of time */ static inline bool isSizeDependent(const SyncFileItem &item) @@ -127,7 +127,7 @@ class OPENCLOUD_SYNC_EXPORT ProgressInfo : public QObject qint64 estimatedBandwidth; /// Estimated time remaining in milliseconds. - quint64 estimatedEta; + uint64_t estimatedEta; }; /** @@ -136,20 +136,13 @@ class OPENCLOUD_SYNC_EXPORT ProgressInfo : public QObject */ struct OPENCLOUD_SYNC_EXPORT Progress { - Progress() - : _progressPerSec(0) - , _prevCompleted(0) - , _initialSmoothing(1.0) - , _completed(0) - , _total(0) - { - } + Progress() = default; /** Returns the estimates about progress per second and eta. */ Estimates estimates() const; - qint64 completed() const; - qint64 remaining() const; + uint64_t completed() const; + uint64_t remaining() const; private: /** @@ -161,19 +154,19 @@ class OPENCLOUD_SYNC_EXPORT ProgressInfo : public QObject * Changes the _completed value and does sanity checks on * _prevCompleted and _total. */ - void setCompleted(qint64 completed); + void setCompleted(uint64_t completed); // Updated by update() - double _progressPerSec; - qint64 _prevCompleted; + double _progressPerSec = 0; + uint64_t _prevCompleted = 0; // Used to get to a good value faster when // progress measurement stats. See update(). - double _initialSmoothing; + double _initialSmoothing = 1; // Set and updated by ProgressInfo - qint64 _completed; - qint64 _total; + uint64_t _completed = 0; + uint64_t _total = 0; friend class ProgressInfo; }; @@ -195,7 +188,7 @@ class OPENCLOUD_SYNC_EXPORT ProgressInfo : public QObject void setProgressComplete(const SyncFileItem &item); - void setProgressItem(const SyncFileItem &item, qint64 completed); + void setProgressItem(const SyncFileItem &item, uint64_t completed); /** * Get the total completion estimate @@ -242,7 +235,7 @@ private Q_SLOTS: Progress _fileProgress; // All size from completed jobs only. - qint64 _totalSizeOfCompletedJobs; + uint64_t _totalSizeOfCompletedJobs; // The fastest observed rate of files per second in this sync. double _maxFilesPerSecond; diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index e19f7c3ca8..de0b891b70 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -384,10 +384,10 @@ void PropagateDownloadFile::startFullDownload() _job->start(); } -qint64 PropagateDownloadFile::committedDiskSpace() const +uint64_t PropagateDownloadFile::committedDiskSpace() const { if (state() == Running) { - return qBound(0LL, _item->_size - _resumeStart - _downloadProgress, _item->_size); + return qBound(0, _item->_size - _resumeStart - _downloadProgress, _item->_size); } return 0; } @@ -481,7 +481,7 @@ void PropagateDownloadFile::slotGetFinished() */ const QByteArray sizeHeader("Content-Length"); bool hasSizeHeader = true; - qint64 bodySize = job->reply()->rawHeader(sizeHeader).toLongLong(&hasSizeHeader); + uint64_t bodySize = job->reply()->rawHeader(sizeHeader).toULongLong(&hasSizeHeader); // Qt removes the content-length header for transparently decompressed HTTP1 replies // but not for HTTP2 or SPDY replies. For these it remains and contains the size @@ -730,7 +730,7 @@ void PropagateDownloadFile::updateMetadata(bool isConflict) } } -void PropagateDownloadFile::slotDownloadProgress(qint64 received, qint64) +void PropagateDownloadFile::slotDownloadProgress(int64_t received, int64_t) { if (!_job) return; diff --git a/src/libsync/propagatedownload.h b/src/libsync/propagatedownload.h index 0da3d4bcbb..78ed9c87d3 100644 --- a/src/libsync/propagatedownload.h +++ b/src/libsync/propagatedownload.h @@ -17,7 +17,6 @@ #include "networkjobs.h" #include "owncloudpropagator.h" -#include #include namespace OCC { @@ -79,7 +78,7 @@ class PropagateDownloadFile : public PropagateItemJob { } void start() override; - qint64 committedDiskSpace() const override; + uint64_t committedDiskSpace() const override; // We think it might finish quickly because it is a small file. bool isLikelyFinishedQuickly() override { return _item->_size < propagator()->smallFileSize(); } @@ -113,14 +112,14 @@ private Q_SLOTS: void updateMetadata(bool isConflict); void abort(PropagatorJob::AbortType abortType) override; - void slotDownloadProgress(qint64, qint64); + void slotDownloadProgress(int64_t, int64_t); void slotChecksumFail(const QString &errMsg); private: void deleteExistingFolder(); - qint64 _resumeStart; - qint64 _downloadProgress; + uint64_t _resumeStart; + uint64_t _downloadProgress; QPointer _job; QFile _tmpFile; bool _deleteExisting; diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 0d13bb670f..c37adfee94 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -133,7 +133,7 @@ void PropagateUploadFileCommon::start() } // Check if we believe that the upload will fail due to remote quota limits - const qint64 quotaGuess = propagator()->_folderQuota.value(QFileInfo(_item->localName()).path(), std::numeric_limits::max()); + const uint64_t quotaGuess = propagator()->_folderQuota.value(QFileInfo(_item->localName()).path(), std::numeric_limits::max()); if (_item->_size > quotaGuess) { // Necessary for blacklisting logic _item->_httpErrorCode = 507; @@ -262,7 +262,7 @@ void PropagateUploadFileCommon::slotStartUpload(CheckSums::Algorithm transmissio doStartUpload(); } -UploadDevice::UploadDevice(const QString &fileName, qint64 start, qint64 size, BandwidthManager *bwm) +UploadDevice::UploadDevice(const QString &fileName, uint64_t start, uint64_t size, BandwidthManager *bwm) : _file(fileName) , _start(start) , _size(size) @@ -301,7 +301,7 @@ bool UploadDevice::open(QIODevice::OpenMode mode) return false; } - _size = qBound(0ll, _size, fileDiskSize - _start); + _size = std::min(_size, fileDiskSize - _start); _read = 0; return QIODevice::open(mode); @@ -328,7 +328,7 @@ qint64 UploadDevice::readData(char *data, qint64 maxlen) } return -1; } - maxlen = qMin(maxlen, _size - _read); + maxlen = std::min(maxlen, _size - _read); if (maxlen <= 0) { return 0; } @@ -352,7 +352,7 @@ qint64 UploadDevice::readData(char *data, qint64 maxlen) return c; } -void UploadDevice::slotJobUploadProgress(qint64 sent, qint64 t) +void UploadDevice::slotJobUploadProgress(int64_t sent, int64_t t) { if (sent == 0 || t == 0) { return; @@ -387,7 +387,7 @@ bool UploadDevice::seek(qint64 pos) if (!QIODevice::seek(pos)) { return false; } - if (pos < 0 || pos > _size) { + if (pos < 0 || static_cast(pos) > _size) { return false; } _read = pos; @@ -449,7 +449,7 @@ void PropagateUploadFileCommon::commonErrorHandling(AbstractNetworkJob *job) const auto path = QFileInfo(_item->localName()).path(); auto quotaIt = propagator()->_folderQuota.find(path); if (quotaIt != propagator()->_folderQuota.end()) { - quotaIt.value() = qMin(quotaIt.value(), _item->_size - 1); + quotaIt.value() = qMin(quotaIt.value(), _item->_size - 1); } else { propagator()->_folderQuota[path] = _item->_size - 1; } @@ -463,7 +463,7 @@ void PropagateUploadFileCommon::commonErrorHandling(AbstractNetworkJob *job) abortWithError(status, errorString); } -void PropagateUploadFileCommon::adjustLastJobTimeout(AbstractNetworkJob *job, qint64 fileSize) +void PropagateUploadFileCommon::adjustLastJobTimeout(AbstractNetworkJob *job, uint64_t fileSize) { // Calculate 3 minutes for each gigabyte of data const auto timeout = std::chrono::minutes(static_cast((3min).count() * fileSize / 1e9)); diff --git a/src/libsync/propagateupload.h b/src/libsync/propagateupload.h index 58b74a4d4f..1c7b20ffb2 100644 --- a/src/libsync/propagateupload.h +++ b/src/libsync/propagateupload.h @@ -16,6 +16,8 @@ #include "owncloudpropagator.h" #include "networkjobs.h" +#include "libsync/bandwidthmanager.h" + #include #include #include @@ -38,7 +40,7 @@ class UploadDevice : public QIODevice { Q_OBJECT public: - UploadDevice(const QString &fileName, qint64 start, qint64 size, BandwidthManager *bwm); + UploadDevice(const QString &fileName, uint64_t start, uint64_t size, BandwidthManager *bwm); ~UploadDevice() override; bool open(QIODevice::OpenMode mode) override; @@ -63,11 +65,11 @@ class UploadDevice : public QIODevice QFile _file; /// Start of the file data to use - qint64 _start = 0; + uint64_t _start = 0; /// Amount of file data after _start to use - qint64 _size = 0; + uint64_t _size = 0; /// Position between _start and _start+_size - qint64 _read = 0; + uint64_t _read = 0; // Bandwidth manager related QPointer _bandwidthManager; @@ -118,8 +120,7 @@ class PUTFileJob : public AbstractNetworkJob void newReplyHook(QNetworkReply *reply) override; Q_SIGNALS: - void uploadProgress(qint64, qint64); - + void uploadProgress(int64_t, int64_t); }; /** @@ -234,7 +235,7 @@ private Q_SLOTS: * * See #6527, enterprise#2480 */ - static void adjustLastJobTimeout(AbstractNetworkJob *job, qint64 fileSize); + static void adjustLastJobTimeout(AbstractNetworkJob *job, uint64_t fileSize); /** Bases headers that need to be sent on the PUT, or in the MOVE for chunking-ng */ QMap headers(); @@ -265,6 +266,6 @@ public Q_SLOTS: void abort(PropagatorJob::AbortType abortType) override; private Q_SLOTS: void slotPutFinished(); - void slotUploadProgress(qint64, qint64); + void slotUploadProgress(int64_t, int64_t); }; } diff --git a/src/libsync/propagateuploadtus.cpp b/src/libsync/propagateuploadtus.cpp index fc5b2f7c0a..85e8dd9a4d 100644 --- a/src/libsync/propagateuploadtus.cpp +++ b/src/libsync/propagateuploadtus.cpp @@ -139,7 +139,7 @@ void PropagateUploadFileTUS::startNextChunk() const quint64 chunkSize = [&] { auto chunkSize = _item->_size - _currentOffset; if (propagator()->account()->capabilities().tusSupport().max_chunk_size) { - chunkSize = std::min(chunkSize, propagator()->account()->capabilities().tusSupport().max_chunk_size); + chunkSize = std::min(chunkSize, propagator()->account()->capabilities().tusSupport().max_chunk_size); } return chunkSize; }(); @@ -168,9 +168,8 @@ void PropagateUploadFileTUS::startNextChunk() connect(job, &SimpleNetworkJob::finishedSignal, this, &PropagateUploadFileTUS::slotChunkFinished); job->addNewReplyHook([job, this](QNetworkReply *reply) { connect(reply, &QNetworkReply::uploadProgress, qobject_cast(job->body().data()), &UploadDevice::slotJobUploadProgress); - connect(reply, &QNetworkReply::uploadProgress, this, [this](qint64 bytesSent, qint64) { - propagator()->reportProgress(*_item, _currentOffset + bytesSent); - }); + connect(reply, &QNetworkReply::uploadProgress, this, + [this](uint64_t bytesSent, uint64_t) { propagator()->reportProgress(*_item, _currentOffset + bytesSent); }); }); job->start(); } @@ -204,7 +203,7 @@ void PropagateUploadFileTUS::slotChunkFinished() return; } - const qint64 offset = job->reply()->rawHeader(uploadOffset()).toLongLong(); + const uint64_t offset = job->reply()->rawHeader(uploadOffset()).toULongLong(); propagator()->reportProgress(*_item, offset); _currentOffset = offset; diff --git a/src/libsync/propagateuploadv1.cpp b/src/libsync/propagateuploadv1.cpp index 88ac3feb04..c4f0cbda92 100644 --- a/src/libsync/propagateuploadv1.cpp +++ b/src/libsync/propagateuploadv1.cpp @@ -44,7 +44,7 @@ void PropagateUploadFileV1::doStartUpload() } propagator()->reportProgress(*_item, 0); - qint64 fileSize = _item->_size; + auto fileSize = _item->_size; auto headers = PropagateUploadFileCommon::headers(); headers[QByteArrayLiteral("OC-Total-Length")] = QByteArray::number(fileSize); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index bcb57606ba..783b589f66 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -317,21 +317,19 @@ void SyncEngine::startSync() } // Check free size on disk first. - const qint64 minFree = criticalFreeSpaceLimit(); - const qint64 freeBytes = Utility::freeDiskSpace(_localPath); - if (freeBytes >= 0) { + const auto minFree = criticalFreeSpaceLimit(); + const auto freeBytes = Utility::freeDiskSpace(_localPath); + if (freeBytes.has_value()) { if (freeBytes < minFree) { qCWarning(lcEngine()) << u"Too little space available at" << _localPath << u". Have" << freeBytes << u"bytes and require at least" << minFree << u"bytes"; - Q_EMIT syncError(tr("Only %1 are available, need at least %2 to start", - "Placeholders are postfixed with file sizes using Utility::octetsToString()") - .arg( - Utility::octetsToString(freeBytes), - Utility::octetsToString(minFree))); + Q_EMIT syncError( + tr("Only %1 are available, need at least %2 to start", "Placeholders are postfixed with file sizes using Utility::octetsToString()") + .arg(Utility::octetsToString(freeBytes.value()), Utility::octetsToString(minFree))); finalize(false); return; } else { - qCInfo(lcEngine) << u"There are" << Utility::octetsToString(freeBytes) << u"available at" << _localPath; + qCInfo(lcEngine) << u"There are" << Utility::octetsToString(freeBytes.value()) << u"available at" << _localPath; } } else { qCWarning(lcEngine) << u"Could not determine free space available at" << _localPath; @@ -649,13 +647,13 @@ void SyncEngine::finalize(bool success) _localDiscoveryStyle = LocalDiscoveryStyle::FilesystemOnly; } -void SyncEngine::slotProgress(const SyncFileItem &item, qint64 current) +void SyncEngine::slotProgress(const SyncFileItem &item, uint64_t current) { _progressInfo->setProgressItem(item, current); Q_EMIT transmissionProgress(*_progressInfo); } -void SyncEngine::updateFileTotal(const SyncFileItem &item, qint64 newSize) +void SyncEngine::updateFileTotal(const SyncFileItem &item, uint64_t newSize) { _progressInfo->updateTotalsForFile(item, newSize); Q_EMIT transmissionProgress(*_progressInfo); diff --git a/src/libsync/syncengine.h b/src/libsync/syncengine.h index 0e84141b4b..1364b7c9dc 100644 --- a/src/libsync/syncengine.h +++ b/src/libsync/syncengine.h @@ -168,8 +168,8 @@ private Q_SLOTS: void slotItemCompleted(const SyncFileItemPtr &item); void slotDiscoveryFinished(); void slotPropagationFinished(bool success); - void slotProgress(const SyncFileItem &item, qint64 curent); - void updateFileTotal(const SyncFileItem &item, qint64 newSize); + void slotProgress(const SyncFileItem &item, uint64_t curent); + void updateFileTotal(const SyncFileItem &item, uint64_t newSize); /** Emit a summary error, unless it was seen before */ void slotSummaryError(const QString &message); diff --git a/src/libsync/syncfileitem.cpp b/src/libsync/syncfileitem.cpp index 2f63a29467..b55132fef6 100644 --- a/src/libsync/syncfileitem.cpp +++ b/src/libsync/syncfileitem.cpp @@ -41,6 +41,11 @@ SyncFileItemPtr SyncFileItem::fromSyncJournalFileRecord(const SyncJournalFileRec return item; } +SyncFileItem::SyncFileItem(const QString &localName) + : _localName(localName) +{ +} + SyncInstruction SyncFileItem::instruction() const { return _instruction; diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index 3431671f64..24fe052932 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -15,11 +15,8 @@ #ifndef SYNCFILEITEM_H #define SYNCFILEITEM_H -#include #include -#include -#include -#include +#include #include @@ -140,25 +137,7 @@ class OPENCLOUD_SYNC_EXPORT SyncFileItem static SyncFileItemPtr fromSyncJournalFileRecord(const SyncJournalFileRecord &rec); - SyncFileItem(const QString &localName = {}) - : _localName(localName) - , _type(ItemTypeUnsupported) - , _direction(None) - , _serverHasIgnoredFiles(false) - , _hasBlacklistEntry(false) - , _status(NoStatus) - , _isRestoration(false) - , _isSelectiveSync(false) - , _httpErrorCode(0) - , _affectedItems(1) - , _modtime(0) - , _size(0) - , _inode(0) - , _previousSize(0) - , _previousModtime(0) - , _relevantDirectoyInstruction(false) - { - } + SyncFileItem(const QString &localName = {}); friend bool operator==(const SyncFileItem &item1, const SyncFileItem &item2) { @@ -266,33 +245,33 @@ class OPENCLOUD_SYNC_EXPORT SyncFileItem */ QString _originalFile; - ItemType _type; - Direction _direction; - bool _serverHasIgnoredFiles; + ItemType _type = ItemTypeUnsupported; + Direction _direction = None; + bool _serverHasIgnoredFiles = false; /// Whether there's an entry in the blacklist table. /// Note: that entry may have retries left, so this can be true /// without the status being FileIgnored. - bool _hasBlacklistEntry; + bool _hasBlacklistEntry = false; // Variables useful to report to the user - Status _status; - bool _isRestoration; // The original operation was forbidden, and this is a restoration - bool _isSelectiveSync; // The file is removed or ignored because it is in the selective sync list - quint16 _httpErrorCode; + Status _status = NoStatus; + bool _isRestoration = false; // The original operation was forbidden, and this is a restoration + bool _isSelectiveSync = false; // The file is removed or ignored because it is in the selective sync list + quint16 _httpErrorCode = 0; RemotePermissions _remotePerm; QString _errorString; // Contains a string only in case of error QString _messageString; // Contains a string only in case of hand crafted events QByteArray _responseTimeStamp; QByteArray _requestId; // X-Request-Id of the failed request - quint32 _affectedItems; // the number of affected items by the operation on this item. + quint32 _affectedItems = 1; // the number of affected items by the operation on this item. // usually this value is 1, but for removes on dirs, it might be much higher. // Variables used by the propagator - time_t _modtime; + time_t _modtime = 0; QString _etag; - qint64 _size; - quint64 _inode; + uint64_t _size = 0; + quint64 _inode = 0; QByteArray _fileId; // This is the value for the 'new' side, matching with _size and _modtime. @@ -304,8 +283,8 @@ class OPENCLOUD_SYNC_EXPORT SyncFileItem QByteArray _checksumHeader; // The size and modtime of the file getting overwritten (on the disk for downloads, on the server for uploads). - qint64 _previousSize; - time_t _previousModtime; + uint64_t _previousSize = 0; + time_t _previousModtime = 0; bool _relevantDirectoyInstruction = false; bool _finished = false; diff --git a/src/libsync/vfs/hydrationjob.cpp b/src/libsync/vfs/hydrationjob.cpp index a7b4a9c0b5..ba1c9e09a6 100644 --- a/src/libsync/vfs/hydrationjob.cpp +++ b/src/libsync/vfs/hydrationjob.cpp @@ -43,8 +43,8 @@ void HydrationJob::start() errorMsg = _job->reply()->errorString(); } - if (_job->contentLength() != -1) { - const auto size = _job->resumeStart() + _job->contentLength(); + if (_job->contentLength()) { + const auto size = _job->resumeStart() + _job->contentLength().value(); if (size != _record.size()) { errorMsg = tr("Unexpected file size transferred. Expected %1 received %2").arg(QString::number(_record.size()), QString::number(size)); // assume that the local and the remote metadata are out of sync diff --git a/src/plugins/vfs/cfapi/cfapiwrapper.cpp b/src/plugins/vfs/cfapi/cfapiwrapper.cpp index 9cfba493fd..4fc81470e4 100644 --- a/src/plugins/vfs/cfapi/cfapiwrapper.cpp +++ b/src/plugins/vfs/cfapi/cfapiwrapper.cpp @@ -527,7 +527,7 @@ OCC::Result OCC::CfApiWrapper::se } } -OCC::Result OCC::CfApiWrapper::createPlaceholderInfo(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId) +OCC::Result OCC::CfApiWrapper::createPlaceholderInfo(const QString &path, time_t modtime, uint64_t size, const QByteArray &fileId) { const auto fileInfo = QFileInfo(path); const auto localBasePath = QDir::toNativeSeparators(fileInfo.path()).toStdWString(); @@ -570,12 +570,12 @@ OCC::Result OCC::CfApiWrapper::createPlaceholderInfo(const QStrin } OCC::Result OCC::CfApiWrapper::updatePlaceholderInfo( - const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath) + const QString &path, time_t modtime, uint64_t size, const QByteArray &fileId, const QString &replacesPath) { return updatePlaceholderState(path, modtime, size, fileId, replacesPath); } -OCC::Result OCC::CfApiWrapper::dehydratePlaceholder(const QString &path, qint64 size, const QByteArray &fileId) +OCC::Result OCC::CfApiWrapper::dehydratePlaceholder(const QString &path, uint64_t size, const QByteArray &fileId) { const auto info = findPlaceholderInfo(path); if (info) { @@ -606,7 +606,7 @@ OCC::Result OCC::CfApiWrapper::de } OCC::Result OCC::CfApiWrapper::convertToPlaceholder( - const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath) + const QString &path, time_t modtime, uint64_t size, const QByteArray &fileId, const QString &replacesPath) { const qint64 result = CfConvertToPlaceholder(Utility::Handle::createHandle(OCC::FileSystem::toFilesystemPath(path)), fileId.data(), static_cast(fileId.size()), CF_CONVERT_FLAG_MARK_IN_SYNC, nullptr, nullptr); diff --git a/src/plugins/vfs/cfapi/cfapiwrapper.h b/src/plugins/vfs/cfapi/cfapiwrapper.h index b3e49fd6c5..54fffd4dab 100644 --- a/src/plugins/vfs/cfapi/cfapiwrapper.h +++ b/src/plugins/vfs/cfapi/cfapiwrapper.h @@ -118,12 +118,12 @@ namespace CfApiWrapper { enum SetPinRecurseMode { NoRecurse = 0, Recurse, ChildrenOnly }; Result setPinState(const QString &path, PinState state, SetPinRecurseMode mode); - Result createPlaceholderInfo(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId); + Result createPlaceholderInfo(const QString &path, time_t modtime, uint64_t size, const QByteArray &fileId); Result updatePlaceholderInfo( - const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath = QString()); + const QString &path, time_t modtime, uint64_t size, const QByteArray &fileId, const QString &replacesPath = QString()); Result convertToPlaceholder( - const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath); - Result dehydratePlaceholder(const QString &path, qint64 size, const QByteArray &fileId); + const QString &path, time_t modtime, uint64_t size, const QByteArray &fileId, const QString &replacesPath); + Result dehydratePlaceholder(const QString &path, uint64_t size, const QByteArray &fileId); Result updatePlaceholderMarkInSync(const Utility::Handle &handle); bool isPlaceHolderInSync(const QString &filePath); } diff --git a/src/plugins/vfs/cfapi/hydrationdevice.cpp b/src/plugins/vfs/cfapi/hydrationdevice.cpp index da7f1518ad..b56973f85b 100644 --- a/src/plugins/vfs/cfapi/hydrationdevice.cpp +++ b/src/plugins/vfs/cfapi/hydrationdevice.cpp @@ -19,7 +19,7 @@ constexpr auto BufferSize = 4_MiB; } -CfApiHydrationJob *CfApiWrapper::HydrationDevice::requestHydration(const CfApiWrapper::CallBackContext &context, qint64 totalSize, QObject *parent) +CfApiHydrationJob *CfApiWrapper::HydrationDevice::requestHydration(const CfApiWrapper::CallBackContext &context, uint64_t totalSize, QObject *parent) { qCInfo(lcCfApiHydrationDevice) << u"Requesting hydration" << context; if (context.vfs->_hydrationJobs.contains(context.transferKey)) { @@ -65,7 +65,7 @@ CfApiHydrationJob *CfApiWrapper::HydrationDevice::requestHydration(const CfApiWr return hydration; } -CfApiWrapper::HydrationDevice::HydrationDevice(const CfApiWrapper::CallBackContext &context, qint64 totalSize, QObject *parent) +CfApiWrapper::HydrationDevice::HydrationDevice(const CfApiWrapper::CallBackContext &context, uint64_t totalSize, QObject *parent) : QIODevice(parent) , _context(context) , _totalSize(totalSize) @@ -123,9 +123,9 @@ qint64 CfApiWrapper::HydrationDevice::writeData(const char *data, qint64 len) _offset += currentBlockLength; // refresh Windows Copy Dialog progress - const LARGE_INTEGER progressTotal = {.QuadPart = _totalSize}; + const LARGE_INTEGER progressTotal = {.QuadPart = static_cast(_totalSize)}; - const LARGE_INTEGER progressCompleted = {.QuadPart = _offset}; + const LARGE_INTEGER progressCompleted = {.QuadPart = static_cast(_offset)}; const qint64 cfReportProgressResult = CfReportProviderProgress(_context.connectionKey, {.QuadPart = _context.transferKey}, progressTotal, progressCompleted); diff --git a/src/plugins/vfs/cfapi/hydrationdevice.h b/src/plugins/vfs/cfapi/hydrationdevice.h index f2a59ee197..dd7acd1d47 100644 --- a/src/plugins/vfs/cfapi/hydrationdevice.h +++ b/src/plugins/vfs/cfapi/hydrationdevice.h @@ -16,9 +16,9 @@ namespace CfApiWrapper { { Q_OBJECT public: - static CfApiHydrationJob *requestHydration(const CfApiWrapper::CallBackContext &context, qint64 totalSize, QObject *parent = nullptr); + static CfApiHydrationJob *requestHydration(const CfApiWrapper::CallBackContext &context, uint64_t totalSize, QObject *parent = nullptr); - HydrationDevice(const CfApiWrapper::CallBackContext &context, qint64 totalSize, QObject *parent = nullptr); + HydrationDevice(const CfApiWrapper::CallBackContext &context, uint64_t totalSize, QObject *parent = nullptr); qint64 readData(char *data, qint64 maxlen) override; qint64 writeData(const char *data, qint64 len) override; @@ -26,9 +26,9 @@ namespace CfApiWrapper { private: CfApiWrapper::CallBackContext _context; // expected total size - qint64 _totalSize; + uint64_t _totalSize = 0; // current offset - qint64 _offset = 0; + uint64_t _offset = 0; QByteArray _buffer; }; diff --git a/test/testdownload.cpp b/test/testdownload.cpp index 0dfcab2464..41dab5de63 100644 --- a/test/testdownload.cpp +++ b/test/testdownload.cpp @@ -27,13 +27,13 @@ class BrokenFakeGetReply : public FakeGetReply Q_OBJECT public: using FakeGetReply::FakeGetReply; - qint64 fakeSize = stopAfter; + uint64_t fakeSize = stopAfter; qint64 bytesAvailable() const override { switch (state) { case State::Ok: - return std::min(size, fakeSize) + QIODevice::bytesAvailable(); + return std::min(size, fakeSize) + QIODevice::bytesAvailable(); default: return FakeGetReply::bytesAvailable(); } @@ -41,7 +41,7 @@ class BrokenFakeGetReply : public FakeGetReply qint64 readData(char *data, qint64 maxlen) override { - qint64 len = std::min(qint64{ fakeSize }, maxlen); + qint64 len = std::min(fakeSize, maxlen); std::fill_n(data, len, payload); size -= len; fakeSize -= len; diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index f97185c07f..499609efc0 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -493,28 +493,28 @@ private Q_SLOTS: QVERIFY(a1); QCOMPARE(a1->instruction(), CSYNC_INSTRUCTION_SYNC); QCOMPARE(a1->_direction, SyncFileItem::Up); - QCOMPARE(a1->_size, qint64(5)); + QCOMPARE(a1->_size, 5); QCOMPARE(Utility::qDateTimeFromTime_t(a1->_modtime), changedMtime); - QCOMPARE(a1->_previousSize, qint64(4)); + QCOMPARE(a1->_previousSize, 4); QCOMPARE(Utility::qDateTimeFromTime_t(a1->_previousModtime), initialMtime); // b2: should have remote size and modtime QVERIFY(b1); QCOMPARE(b1->instruction(), CSYNC_INSTRUCTION_SYNC); QCOMPARE(b1->_direction, SyncFileItem::Down); - QCOMPARE(b1->_size, qint64(17)); + QCOMPARE(b1->_size, 17); QCOMPARE(Utility::qDateTimeFromTime_t(b1->_modtime), changedMtime); - QCOMPARE(b1->_previousSize, qint64(16)); + QCOMPARE(b1->_previousSize, 16); QCOMPARE(Utility::qDateTimeFromTime_t(b1->_previousModtime), initialMtime); // c1: conflicts are downloads, so remote size and modtime QVERIFY(c1); QCOMPARE(c1->instruction(), CSYNC_INSTRUCTION_CONFLICT); QCOMPARE(c1->_direction, SyncFileItem::None); - QCOMPARE(c1->_size, qint64(25)); + QCOMPARE(c1->_size, 25); QCOMPARE(Utility::qDateTimeFromTime_t(c1->_modtime), changedMtime2); - QCOMPARE(c1->_previousSize, qint64(26)); + QCOMPARE(c1->_previousSize, 26); QCOMPARE(Utility::qDateTimeFromTime_t(c1->_previousModtime), changedMtime); }); diff --git a/test/testutils/syncenginetestutils.cpp b/test/testutils/syncenginetestutils.cpp index 98a0ca3b98..018ae1f42e 100644 --- a/test/testutils/syncenginetestutils.cpp +++ b/test/testutils/syncenginetestutils.cpp @@ -453,7 +453,7 @@ qint64 FakePropfindReply::bytesAvailable() const qint64 FakePropfindReply::readData(char *data, qint64 maxlen) { - qint64 len = std::min(qint64 { payload.size() }, maxlen); + uint64_t len = std::min(payload.size(), maxlen); std::copy(payload.cbegin(), payload.cbegin() + len, data); payload.remove(0, static_cast(len)); return len; @@ -679,7 +679,7 @@ qint64 FakeGetReply::bytesAvailable() const qint64 FakeGetReply::readData(char *data, qint64 maxlen) { - qint64 len = std::min(qint64 { size }, maxlen); + auto len = std::min(size, maxlen); std::fill_n(data, len, payload); size -= len; return len; @@ -709,7 +709,7 @@ void FakePayloadReply::respond() qint64 FakePayloadReply::readData(char *buf, qint64 max) { - max = qMin(max, _body.size()); + max = qMin(max, _body.size()); memcpy(buf, _body.constData(), max); _body = _body.mid(max); return max; @@ -757,7 +757,7 @@ void FakeErrorReply::slotSetFinished() qint64 FakeErrorReply::readData(char *buf, qint64 max) { - max = qMin(max, _body.size()); + max = qMin(max, _body.size()); memcpy(buf, _body.constData(), max); _body = _body.mid(max); return max; diff --git a/test/testutils/syncenginetestutils.h b/test/testutils/syncenginetestutils.h index 32fda6451d..08bec06179 100644 --- a/test/testutils/syncenginetestutils.h +++ b/test/testutils/syncenginetestutils.h @@ -390,9 +390,9 @@ class FakeGetReply : public FakeReply }; Q_ENUM(State); - const FileInfo *fileInfo; - char payload; - qint64 size; + const FileInfo *fileInfo = nullptr; + char payload = 0; + uint64_t size = 0; State state = State::Ok; const std::pair _range; diff --git a/test/testxmlparse.cpp b/test/testxmlparse.cpp index 00bdf34508..6b7f876e80 100644 --- a/test/testxmlparse.cpp +++ b/test/testxmlparse.cpp @@ -104,7 +104,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(parser.parse(testXml, &sizes, QStringLiteral("/oc/remote.php/webdav/sharefolder"))); QVERIFY(_success); @@ -176,7 +176,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(false == parser.parse(testXml, &sizes, QStringLiteral("/oc/remote.php/webdav/sharefolder"))); // verify false QVERIFY(!_success); @@ -197,7 +197,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(false == parser.parse(testXml, &sizes, QStringLiteral("/oc/remote.php/webdav/sharefolder"))); // verify false QVERIFY(!_success); @@ -217,7 +217,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(false == parser.parse(testXml, &sizes, QStringLiteral("/oc/remote.php/webdav/sharefolder"))); // verify false QVERIFY(!_success); @@ -254,7 +254,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(!parser.parse(testXml, &sizes, QStringLiteral("/oc/remote.php/webdav/sharefolder"))); QVERIFY(!_success); } @@ -317,7 +317,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(false == parser.parse(testXml, &sizes, QStringLiteral("/oc/remote.php/webdav/sharefolder"))); QVERIFY(!_success); } @@ -380,7 +380,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(false == parser.parse(testXml, &sizes, QStringLiteral("/oc/remote.php/webdav/sharefolder"))); QVERIFY(!_success); } @@ -442,7 +442,7 @@ private Q_SLOTS: connect(&parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated); connect(&parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully); - QHash sizes; + QHash sizes; QVERIFY(parser.parse(testXml, &sizes, QString::fromUtf8("/รค"))); QVERIFY(_success);