diff --git a/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.cpp b/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.cpp index f54bbe127..2233e6d6d 100644 --- a/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.cpp +++ b/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.cpp @@ -18,7 +18,6 @@ #include "csvfullfilelistwithcursorjob.h" #include "libcommonserver/utility/utility.h" -#include "update_detection/file_system_observer/snapshot/snapshotitem.h" #ifdef _WIN32 #include "reconciliation/platform_inconsistency_checker/platforminconsistencycheckerutility.h" @@ -32,7 +31,7 @@ static const std::string endOfFileDelimiter("#EOF"); namespace KDC { -SnapshotItemHandler::SnapshotItemHandler(log4cplus::Logger logger) : _logger(logger) {}; +SnapshotItemHandler::SnapshotItemHandler(log4cplus::Logger logger) : _logger(logger) {} void SnapshotItemHandler::logError(const std::wstring &methodName, const std::wstring &stdErrorType, const std::string &str, const std::exception &exc) { diff --git a/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.h b/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.h index 2d42ed7d9..5cf49503f 100644 --- a/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.h +++ b/src/libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.h @@ -39,7 +39,7 @@ class SnapshotItemHandler { CsvIndexEnd }; - inline static void incrementCsvIndex(CsvIndex &index) { index = static_cast(static_cast(index) + 1); }; + inline static void incrementCsvIndex(CsvIndex &index) { index = static_cast(static_cast(index) + 1); } struct ParsingState { CsvIndex index{CsvIndexId}; // The index of the column that is currently read. diff --git a/src/libsyncengine/jobs/network/API_v2/jsonfullfilelistwithcursorjob.h b/src/libsyncengine/jobs/network/API_v2/jsonfullfilelistwithcursorjob.h index b538a573b..56abe26c9 100644 --- a/src/libsyncengine/jobs/network/API_v2/jsonfullfilelistwithcursorjob.h +++ b/src/libsyncengine/jobs/network/API_v2/jsonfullfilelistwithcursorjob.h @@ -19,7 +19,6 @@ #pragma once #include "abstracttokennetworkjob.h" -#include "update_detection/file_system_observer/snapshot/snapshotitem.h" namespace KDC { diff --git a/src/libsyncengine/update_detection/file_system_observer/localfilesystemobserverworker.cpp b/src/libsyncengine/update_detection/file_system_observer/localfilesystemobserverworker.cpp index 0654260b5..9c3e50c67 100644 --- a/src/libsyncengine/update_detection/file_system_observer/localfilesystemobserverworker.cpp +++ b/src/libsyncengine/update_detection/file_system_observer/localfilesystemobserverworker.cpp @@ -19,7 +19,6 @@ #include "localfilesystemobserverworker.h" #include "libcommon/utility/utility.h" #include "libcommon/log/sentry/ptraces.h" - #include "libcommonserver/io/filestat.h" #include "libcommonserver/io/iohelper.h" #include "libcommonserver/utility/utility.h" diff --git a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp index 519219000..69bd1ce1e 100644 --- a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp +++ b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp @@ -18,10 +18,10 @@ #include "remotefilesystemobserverworker.h" #include "jobs/jobmanager.h" -#include "../../jobs/network/API_v2/csvfullfilelistwithcursorjob.h" -#include "../../jobs/network/API_v2/getfileinfojob.h" -#include "../../jobs/network/API_v2/longpolljob.h" -#include "../../jobs/network/API_v2/continuefilelistwithcursorjob.h" +#include "jobs/network/API_v2/csvfullfilelistwithcursorjob.h" +#include "jobs/network/API_v2/getfileinfojob.h" +#include "jobs/network/API_v2/longpolljob.h" +#include "jobs/network/API_v2/continuefilelistwithcursorjob.h" #ifdef _WIN32 #include "reconciliation/platform_inconsistency_checker/platforminconsistencycheckerutility.h" #endif @@ -32,6 +32,7 @@ #include "requests/parameterscache.h" #include "requests/exclusiontemplatecache.h" #include "utility/jsonparserutility.h" + #ifdef __APPLE__ #include "utility/utility.h" #endif diff --git a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h index 4a19ad6f6..03db2ee49 100644 --- a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h +++ b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h @@ -19,8 +19,8 @@ #pragma once #include "filesystemobserverworker.h" - #include "jobs/network/networkjobsparams.h" +#include "update_detection/file_system_observer/snapshot/snapshotitem.h" #include diff --git a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp index 638248d2c..23c6c2463 100644 --- a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp +++ b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp @@ -47,6 +47,7 @@ Snapshot &Snapshot::operator=(Snapshot &other) { _items = other._items; _isValid = other._isValid; + _copy = true; } return *this; @@ -236,7 +237,7 @@ bool Snapshot::path(const NodeId &itemId, SyncPath &path, bool &ignore) const no } bool ok = true; - std::deque names; + std::deque> ancestors; bool parentIsRoot = false; NodeId id = itemId; @@ -244,7 +245,14 @@ bool Snapshot::path(const NodeId &itemId, SyncPath &path, bool &ignore) const no const std::scoped_lock lock(_mutex); while (!parentIsRoot) { if (const auto it = _items.find(id); it != _items.end()) { - names.push_back(it->second.name()); + if (_copy) { + if (!it->second.path().empty()) { + path = it->second.path(); + break; + }; + } + + ancestors.push_back({it->first, it->second.name()}); id = it->second.parentId(); parentIsRoot = id == _rootFolderId; continue; @@ -256,16 +264,25 @@ bool Snapshot::path(const NodeId &itemId, SyncPath &path, bool &ignore) const no } // Construct path - SyncPath tmpParentPath; - while (!names.empty()) { - path /= names.back(); - names.pop_back(); + SyncPath tmpParentPath(path); + while (!ancestors.empty()) { + path /= ancestors.back().second; + if (_copy) { + const auto it = _items.find(ancestors.back().first); + assert(it != _items.end()); + it->second.setPath(path); + } + ancestors.pop_back(); + + // Trick to ignore items with pattern like "X:" in their name on Windows - Begin if (path.parent_path() != tmpParentPath) { ignore = true; return false; } tmpParentPath = path; + // Trick to ignore items with pattern like "X:" in their name on Windows - End } + return ok; } diff --git a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.h b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.h index 37c522299..9b22ab756 100644 --- a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.h +++ b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.h @@ -93,6 +93,8 @@ class Snapshot : public SharedObject { NodeId _rootFolderId; std::unordered_map _items; // key: id bool _isValid = false; + bool _copy = false; // false for a real time snapshot, true for a copy + mutable std::recursive_mutex _mutex; }; diff --git a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.cpp b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.cpp index aa6927160..f4356c88f 100644 --- a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.cpp +++ b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.cpp @@ -58,6 +58,7 @@ void SnapshotItem::copyExceptChildren(const SnapshotItem &other) { _contentChecksum = other.contentChecksum(); _canWrite = other.canWrite(); _canShare = other.canShare(); + _path = other.path(); } void SnapshotItem::addChildren(const NodeId &id) { diff --git a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h index a4a48dbef..1aa25f4c0 100644 --- a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h +++ b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h @@ -26,6 +26,8 @@ namespace KDC { +class Snapshot; + class SnapshotItem { public: SnapshotItem(); @@ -65,6 +67,7 @@ class SnapshotItem { void setCanWrite(const bool canWrite) { _canWrite = canWrite; } [[nodiscard]] bool canShare() const { return _canShare; } void setCanShare(bool canShare) { _canShare = canShare; } + SnapshotItem &operator=(const SnapshotItem &other); void copyExceptChildren(const SnapshotItem &other); @@ -87,6 +90,14 @@ class SnapshotItem { bool _canShare = true; std::unordered_set _childrenIds; + + mutable SyncPath _path; // The item relative path. Cached value. To use only on a snapshot copy, not a real time one. + + [[nodiscard]] SyncPath path() const { return _path; } + void setPath(const SyncPath &path) const { _path = path; } + + friend class Snapshot; + // friend bool Snapshot::path(const NodeId &, SyncPath &, bool &) const noexcept; }; } // namespace KDC diff --git a/test/libsyncengine/jobs/network/testnetworkjobs.cpp b/test/libsyncengine/jobs/network/testnetworkjobs.cpp index ca6c3bc54..cec872cdf 100644 --- a/test/libsyncengine/jobs/network/testnetworkjobs.cpp +++ b/test/libsyncengine/jobs/network/testnetworkjobs.cpp @@ -40,20 +40,21 @@ #include "jobs/network/API_v2/getsizejob.h" #include "jobs/jobmanager.h" #include "network/proxy.h" +#include "utility/jsonparserutility.h" +#include "requests/parameterscache.h" +#include "jobs/network/getappversionjob.h" +#include "jobs/network/directdownloadjob.h" #include "libcommon/keychainmanager/keychainmanager.h" #include "libcommonserver/utility/utility.h" #include "libcommonserver/io/filestat.h" #include "libcommonserver/io/iohelper.h" #include "libparms/db/parmsdb.h" -#include "utility/jsonparserutility.h" -#include "requests/parameterscache.h" + #include "test_utility/localtemporarydirectory.h" #include "test_utility/remotetemporarydirectory.h" -#include - -#include "jobs/network/getappversionjob.h" #include "test_utility/testhelpers.h" -#include "jobs/network/directdownloadjob.h" + +#include using namespace CppUnit; diff --git a/test/libsyncengine/jobs/network/testsnapshotitemhandler.cpp b/test/libsyncengine/jobs/network/testsnapshotitemhandler.cpp index 5ecdad0bb..8d6c11d4e 100644 --- a/test/libsyncengine/jobs/network/testsnapshotitemhandler.cpp +++ b/test/libsyncengine/jobs/network/testsnapshotitemhandler.cpp @@ -18,7 +18,6 @@ #include "testsnapshotitemhandler.h" #include "libsyncengine/jobs/network/API_v2/csvfullfilelistwithcursorjob.h" - #include "libcommonserver/log/log.h" diff --git a/test/libsyncengine/jobs/network/testsnapshotitemhandler.h b/test/libsyncengine/jobs/network/testsnapshotitemhandler.h index a66cbee97..dc2247c7e 100644 --- a/test/libsyncengine/jobs/network/testsnapshotitemhandler.h +++ b/test/libsyncengine/jobs/network/testsnapshotitemhandler.h @@ -24,7 +24,6 @@ using namespace CppUnit; namespace KDC { -class SnapshotItem; class TestSnapshotItemHandler : public CppUnit::TestFixture { public: diff --git a/test/libsyncengine/propagation/operation_sorter/testoperationsorterworker.cpp b/test/libsyncengine/propagation/operation_sorter/testoperationsorterworker.cpp index c277ff5c3..6e4224da4 100644 --- a/test/libsyncengine/propagation/operation_sorter/testoperationsorterworker.cpp +++ b/test/libsyncengine/propagation/operation_sorter/testoperationsorterworker.cpp @@ -17,10 +17,10 @@ */ #include "testoperationsorterworker.h" - #include "test_utility/testhelpers.h" #include + using namespace CppUnit; namespace KDC { diff --git a/test/libsyncengine/reconciliation/conflict_finder/testconflictfinderworker.cpp b/test/libsyncengine/reconciliation/conflict_finder/testconflictfinderworker.cpp index c4d6e872e..ff9aa26af 100644 --- a/test/libsyncengine/reconciliation/conflict_finder/testconflictfinderworker.cpp +++ b/test/libsyncengine/reconciliation/conflict_finder/testconflictfinderworker.cpp @@ -17,7 +17,6 @@ */ #include "testconflictfinderworker.h" - #include "test_utility/testhelpers.h" using namespace CppUnit; diff --git a/test/libsyncengine/update_detection/file_system_observer/testsnapshot.cpp b/test/libsyncengine/update_detection/file_system_observer/testsnapshot.cpp index 8219246be..7f149ac62 100644 --- a/test/libsyncengine/update_detection/file_system_observer/testsnapshot.cpp +++ b/test/libsyncengine/update_detection/file_system_observer/testsnapshot.cpp @@ -18,7 +18,6 @@ #include "testsnapshot.h" #include "test_utility/testhelpers.h" - #include "db/syncdb.h" #include "requests/parameterscache.h"