Skip to content

Commit

Permalink
Use seconds resolution for minimumFileAgeForUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Jun 16, 2023
1 parent 17a864b commit 7c55d9a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ int main(int argc, char **argv)
ctx.account->setDavDisplayName(data.value(QStringLiteral("display-name")).toString());

// much lower age than the default since this utility is usually made to be run right after a change in the tests
SyncEngine::minimumFileAgeForUpload = std::chrono::milliseconds(0);
SyncEngine::minimumFileAgeForUpload = std::chrono::seconds(0);
sync(ctx);
});
userJob->start();
Expand Down
13 changes: 7 additions & 6 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@

#include "libsync/theme.h"

#include <QNetworkAccessManager>
#include <QFileInfo>
#include <QDir>
#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>

#include <chrono>
#include <cmath>
#include <cstring>

using namespace std::chrono_literals;

Expand All @@ -58,11 +59,11 @@ Q_LOGGING_CATEGORY(lcPropagateUploadNG, "sync.propagator.upload.ng", QtInfoMsg)
static bool fileIsStillChanging(const SyncFileItem &item)
{
const QDateTime modtime = Utility::qDateTimeFromTime_t(item._modtime);
const qint64 msSinceMod = modtime.msecsTo(QDateTime::currentDateTimeUtc());
const auto secondsSinceMod = std::chrono::seconds(modtime.secsTo(QDateTime::currentDateTimeUtc()));

return std::chrono::milliseconds(msSinceMod) < SyncEngine::minimumFileAgeForUpload
return secondsSinceMod < SyncEngine::minimumFileAgeForUpload
// if the mtime is too much in the future we *do* upload the file
&& msSinceMod > -10000;
&& secondsSinceMod > -1s;
}

PUTFileJob::PUTFileJob(AccountPtr account, const QUrl &url, const QString &path, std::unique_ptr<QIODevice> &&device, const QMap<QByteArray, QByteArray> &headers, int chunk, QObject *parent)
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace OCC {
Q_LOGGING_CATEGORY(lcEngine, "sync.engine", QtInfoMsg)

// doc in header
std::chrono::milliseconds SyncEngine::minimumFileAgeForUpload(2000);
std::chrono::seconds SyncEngine::minimumFileAgeForUpload(2s);

SyncEngine::SyncEngine(AccountPtr account, const QUrl &baseUrl, const QString &localPath,
const QString &remotePath, OCC::SyncJournalDb *journal)
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
* To avoid that, uploads of files where the distance between the mtime and the
* current time is less than this duration are skipped.
*/
static std::chrono::milliseconds minimumFileAgeForUpload;
static std::chrono::seconds minimumFileAgeForUpload;

/**
* Control whether local discovery should read from filesystem or db.
Expand Down
2 changes: 1 addition & 1 deletion test/testutils/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ FakeFolder::FakeFolder(const FileInfo &fileTemplate, OCC::Vfs::Mode vfsMode, boo
: _localModifier(_tempDir.path())
{
// Needs to be done once
OCC::SyncEngine::minimumFileAgeForUpload = std::chrono::milliseconds(0);
OCC::SyncEngine::minimumFileAgeForUpload = 0s;

QDir rootDir { _tempDir.path() };
qDebug() << "FakeFolder operating on" << rootDir;
Expand Down

0 comments on commit 7c55d9a

Please sign in to comment.