Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/protocolitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ QDateTime ProtocolItem::timestamp() const
return _timestamp;
}

qint64 ProtocolItem::size() const
uint64_t ProtocolItem::size() const
{
return _size;
}
Expand Down
10 changes: 5 additions & 5 deletions src/gui/protocolitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OPENCLOUD_GUI_EXPORT ProtocolItem
*/
QDateTime timestamp() const;

qint64 size() const;
uint64_t size() const;

SyncFileItem::Status status() const;

Expand All @@ -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;
};
Expand Down
42 changes: 4 additions & 38 deletions src/gui/selectivesyncwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'))) {
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -391,39 +390,6 @@ QSet<QString> 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;
Expand Down
6 changes: 1 addition & 5 deletions src/gui/selectivesyncwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#pragma once
#include "accountfwd.h"
#include <QDialog>
#include <QTreeWidget>
#include <QUrl>

Expand All @@ -41,9 +40,6 @@ class SelectiveSyncWidget : public QWidget
/// Returns a list of blacklisted paths, each including the trailing /
QSet<QString> 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<QString> &oldBlackList = {});

Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/gui/syncrunfilelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "filesystem.h"
#include <qfileinfo.h>

using namespace OCC::FileSystem::SizeLiterals;

namespace {
auto dateTimeStr(const QDateTime &dt = QDateTime::currentDateTimeUtc())
{
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/common/checksums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/common/filesystembase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/common/ownsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/libsync/common/syncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions src/libsync/common/syncjournaldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/common/syncjournalfilerecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/common/syncjournalfilerecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
19 changes: 8 additions & 11 deletions src/libsync/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -116,26 +114,25 @@ QByteArray Utility::userAgentString()
.toLatin1();
}

qint64 Utility::freeDiskSpace(const QString &path)
std::optional<uint64_t> 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<const wchar_t *>(FileSystem::longWinPath(path).utf16()), &freeBytes, nullptr, nullptr)) {
return freeBytes.QuadPart;
}
#endif
return -1;
return {};
}

QString Utility::compactFormatDouble(double value, int prec, const QString &unit)
Expand Down
5 changes: 2 additions & 3 deletions src/libsync/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <QMap>
#include <QMetaEnum>
#include <QString>
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The include #include <QUrl> was removed, but the header still uses QUrl as a parameter type in function declarations on lines 204 and 207. While QUrlQuery includes QUrl transitively in some Qt versions, relying on transitive includes is fragile and can break with different Qt versions or build configurations. The #include <QUrl> should be kept.

Suggested change
#include <QString>
#include <QString>
#include <QUrl>

Copilot uses AI. Check for mistakes.
#include <QUrl>
#include <QUrlQuery>

#include <functional>
Expand All @@ -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();

/**
Expand All @@ -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<uint64_t> freeDiskSpace(const QString &path);

/**
* @brief compactFormatDouble - formats a double value human readable.
Expand Down
5 changes: 3 additions & 2 deletions src/libsync/discoveryinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/discoveryinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading