Skip to content

Commit

Permalink
Merge branch 'develop' into KDESKTOP-1245-Exclude-files-folders-with-…
Browse files Browse the repository at this point in the history
…name-length-255-characters-2
  • Loading branch information
ClementKunz authored Oct 18, 2024
2 parents 0ce82aa + c740c66 commit af0d5d2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 41 deletions.
33 changes: 11 additions & 22 deletions src/libsyncengine/progress/progressinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

namespace KDC {

ProgressInfo::ProgressInfo(std::shared_ptr<SyncPal> syncPal) :
_syncPal(syncPal), _totalSizeOfCompletedJobs(0), _maxFilesPerSecond(0), _maxBytesPerSecond(0), _update(false) {
ProgressInfo::ProgressInfo(std::shared_ptr<SyncPal> syncPal) : _syncPal(syncPal) {
reset();
}

Expand Down Expand Up @@ -77,44 +76,43 @@ void ProgressInfo::updateEstimates() {
}

void ProgressInfo::initProgress(const SyncFileItem &item) {
SyncPath path = item.newPath().has_value() ? item.newPath().value() : item.path();
const SyncPath path = item.newPath().has_value() ? item.newPath().value() : item.path();
ProgressItem progressItem;
progressItem.setItem(item);
progressItem.progress().setTotal(item.size());
progressItem.progress().setCompleted(0);

_currentItems[path].push(progressItem);
_currentItems[Utility::normalizedSyncPath(path)].push(progressItem);

_fileProgress.setTotal(_fileProgress.total() + 1);
_sizeProgress.setTotal(_sizeProgress.total() + item.size());
}

bool ProgressInfo::getSyncFileItem(const SyncPath &path, SyncFileItem &item) {
auto it = _currentItems.find(path);
if (_currentItems.find(path) == _currentItems.end() || it->second.empty()) {
const auto it = _currentItems.find(Utility::normalizedSyncPath(path));
if (it == _currentItems.end() || it->second.empty()) {
return false;
}
item = it->second.front().item();
return true;
}

void ProgressInfo::setProgress(const SyncPath &path, int64_t completed) {
auto it = _currentItems.find(path);
void ProgressInfo::setProgress(const SyncPath &path, const int64_t completed) {
const auto it = _currentItems.find(Utility::normalizedSyncPath(path));
if (it == _currentItems.end() || it->second.empty()) {
return;
}

SyncFileItem &item = it->second.front().item();
if (!shouldCountProgress(item)) {
if (const SyncFileItem &item = it->second.front().item(); !shouldCountProgress(item)) {
return;
}

it->second.front().progress().setCompleted(completed);
recomputeCompletedSize();
}

void ProgressInfo::setProgressComplete(const SyncPath &path, SyncFileStatus status) {
auto it = _currentItems.find(path);
void ProgressInfo::setProgressComplete(const SyncPath &path, const SyncFileStatus status) {
const auto it = _currentItems.find(Utility::normalizedSyncPath(path));
if (it == _currentItems.end() || it->second.empty()) {
return;
}
Expand All @@ -135,7 +133,7 @@ void ProgressInfo::setProgressComplete(const SyncPath &path, SyncFileStatus stat

it->second.pop();
if (it->second.empty()) {
_currentItems.erase(path);
_currentItems.erase(Utility::normalizedSyncPath(path));
}
recomputeCompletedSize();
}
Expand Down Expand Up @@ -183,15 +181,6 @@ bool ProgressInfo::trustEta() const {
return totalProgress().estimatedEta() < 100 * optimisticEta();
}

Estimates ProgressInfo::fileProgress(const SyncFileItem &item) {
auto it = _currentItems.find(item.path());
if (it == _currentItems.end() || it->second.empty()) {
return Estimates();
}

return it->second.front().progress().estimates();
}

void ProgressInfo::recomputeCompletedSize() {
int64_t r = _totalSizeOfCompletedJobs;
for (auto &itemElt: _currentItems) {
Expand Down
33 changes: 16 additions & 17 deletions src/libsyncengine/progress/progressinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ class SyncPal;

class ProgressInfo {
public:
ProgressInfo(std::shared_ptr<SyncPal> syncPal);
explicit ProgressInfo(std::shared_ptr<SyncPal> syncPal);
~ProgressInfo();

void reset();
inline void setUpdate(bool value) { _update = value; }
inline bool update() const { return _update; }
void setUpdate(bool value) { _update = value; }
[[nodiscard]] bool update() const { return _update; }
void updateEstimates();
void initProgress(const SyncFileItem &item);
void setProgress(const SyncPath &path, int64_t completed);
void setProgressComplete(const SyncPath &path, SyncFileStatus status);
bool getSyncFileItem(const SyncPath &path, SyncFileItem &item);

inline int64_t totalFiles() const { return _fileProgress.total(); }
inline int64_t completedFiles() const { return _fileProgress.completed(); }
inline int64_t totalSize() const { return _sizeProgress.total(); }
inline int64_t completedSize() const { return _sizeProgress.completed(); }
inline int64_t currentFile() const { return completedFiles(); }
Estimates totalProgress() const;
[[nodiscard]] int64_t totalFiles() const { return _fileProgress.total(); }
[[nodiscard]] int64_t completedFiles() const { return _fileProgress.completed(); }
[[nodiscard]] int64_t totalSize() const { return _sizeProgress.total(); }
[[nodiscard]] int64_t completedSize() const { return _sizeProgress.completed(); }
[[nodiscard]] int64_t currentFile() const { return completedFiles(); }
[[nodiscard]] Estimates totalProgress() const;

private:
std::shared_ptr<SyncPal> _syncPal;
Expand All @@ -60,16 +60,15 @@ class ProgressInfo {
// DELETE a file and CREATE a directory with exact same name)
Progress _sizeProgress;
Progress _fileProgress;
int64_t _totalSizeOfCompletedJobs;
double _maxFilesPerSecond;
double _maxBytesPerSecond;
bool _update;
int64_t _totalSizeOfCompletedJobs{0};
double _maxFilesPerSecond{0.0};
double _maxBytesPerSecond{0.0};
bool _update{false};

int64_t optimisticEta() const;
bool trustEta() const;
Estimates fileProgress(const SyncFileItem &item);
[[nodiscard]] int64_t optimisticEta() const;
[[nodiscard]] bool trustEta() const;
void recomputeCompletedSize();
bool isSizeDependent(const SyncFileItem &item) const;
[[nodiscard]] bool isSizeDependent(const SyncFileItem &item) const;
};

} // namespace KDC
2 changes: 2 additions & 0 deletions src/libsyncengine/progress/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class SyncFileItem {

inline bool isDirectory() const { return _type == NodeType::Directory; }

bool operator==(const SyncFileItem &) const = default;

private:
NodeType _type{NodeType::Unknown};
SyncPath _path; // Sync folder relative filesystem path
Expand Down
3 changes: 1 addition & 2 deletions src/libsyncengine/syncpal/syncpal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,7 @@ bool SyncPal::existOnServer(const SyncPath &path) const {
bool SyncPal::canShareItem(const SyncPath &path) const {
// Path is normalized on server side
const SyncPath normalizedPath = Utility::normalizedSyncPath(path);
const NodeId nodeId = _remoteSnapshot->itemId(path);
if (!nodeId.empty()) {
if (const NodeId nodeId = _remoteSnapshot->itemId(normalizedPath); !nodeId.empty()) {
return _remoteSnapshot->canShare(nodeId);
}
return false;
Expand Down
47 changes: 47 additions & 0 deletions test/libsyncengine/syncpal/testsyncpal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,53 @@ void TestSyncPal::testCopySnapshots() {
CPPUNIT_ASSERT(_syncPal->snapshot(ReplicaSide::Local, true)->isValid() !=
_syncPal->snapshot(ReplicaSide::Local, false)->isValid());
}
void TestSyncPal::testSyncFileItem() {
_syncPal->_progressInfo = std::make_shared<ProgressInfo>(_syncPal);

CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(0), _syncPal->_progressInfo->completedSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(0), _syncPal->_progressInfo->completedFiles());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(0), _syncPal->_progressInfo->totalSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(0), _syncPal->_progressInfo->totalFiles());

const SyncPath nfcPath = SyncPath(Str("/") + testhelpers::makeNfcSyncName() + Str("/test.txt")).native();
const SyncPath nfdPath = SyncPath(Str("/") + testhelpers::makeNfdSyncName() + Str("/test.txt")).native();
SyncFileItem initItem;
initItem.setType(NodeType::File);
initItem.setPath(nfcPath);
initItem.setLocalNodeId("l123");
initItem.setDirection(SyncDirection::Up);
initItem.setInstruction(SyncFileInstruction::Put);
initItem.setSize(testhelpers::defaultFileSize);
initItem.setModTime(testhelpers::defaultTime);
_syncPal->initProgress(initItem);

SyncFileItem testItem;
CPPUNIT_ASSERT(_syncPal->getSyncFileItem(nfcPath, testItem));
CPPUNIT_ASSERT(testItem == initItem);
CPPUNIT_ASSERT(_syncPal->getSyncFileItem(nfdPath, testItem));
CPPUNIT_ASSERT(testItem == initItem);

CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(0), _syncPal->_progressInfo->completedSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(0), _syncPal->_progressInfo->completedFiles());
CPPUNIT_ASSERT_EQUAL(testhelpers::defaultFileSize, _syncPal->_progressInfo->totalSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(1), _syncPal->_progressInfo->totalFiles());

constexpr int64_t progress = 15;
_syncPal->setProgress(nfdPath, progress);
CPPUNIT_ASSERT(_syncPal->getSyncFileItem(nfdPath, testItem));

CPPUNIT_ASSERT_EQUAL(progress, _syncPal->_progressInfo->completedSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(0), _syncPal->_progressInfo->completedFiles());
CPPUNIT_ASSERT_EQUAL(testhelpers::defaultFileSize, _syncPal->_progressInfo->totalSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(1), _syncPal->_progressInfo->totalFiles());

_syncPal->setProgressComplete(nfdPath, SyncFileStatus::Success);

CPPUNIT_ASSERT_EQUAL(testhelpers::defaultFileSize, _syncPal->_progressInfo->completedSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(1), _syncPal->_progressInfo->completedFiles());
CPPUNIT_ASSERT_EQUAL(testhelpers::defaultFileSize, _syncPal->_progressInfo->totalSize());
CPPUNIT_ASSERT_EQUAL(static_cast<int64_t>(1), _syncPal->_progressInfo->totalFiles());
}

void TestSyncPal::testAll() {
// Start sync
Expand Down
3 changes: 3 additions & 0 deletions test/libsyncengine/syncpal/testsyncpal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TestSyncPal : public CppUnit::TestFixture {
CPPUNIT_TEST(testSnapshot);
CPPUNIT_TEST(testCopySnapshots);
CPPUNIT_TEST(testOperationSet);
CPPUNIT_TEST(testSyncFileItem);
CPPUNIT_TEST_SUITE_END();

public:
Expand All @@ -50,6 +51,8 @@ class TestSyncPal : public CppUnit::TestFixture {
void testOperationSet();
void testCopySnapshots();

void testSyncFileItem();

void testAll();
void testConflictQueue();
bool exec_case_6_4();
Expand Down

0 comments on commit af0d5d2

Please sign in to comment.