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
herve-er authored Oct 18, 2024
2 parents 95065b5 + 94d04b7 commit 0ce82aa
Show file tree
Hide file tree
Showing 37 changed files with 899 additions and 352 deletions.
1 change: 0 additions & 1 deletion src/libcommon/theme/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <QtCore>
#include <QtGui>
#include <QStyle>
#include <QApplication>
#include <QSslSocket>

namespace KDC {
Expand Down
4 changes: 2 additions & 2 deletions src/libcommonserver/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Vfs : public QObject {
* new placeholder shall supersede, for rename-replace actions with new downloads,
* for example.
*/
virtual bool convertToPlaceholder(const QString &path, const KDC::SyncFileItem &item, bool &needRestart) = 0;
virtual bool convertToPlaceholder(const QString &path, const KDC::SyncFileItem &item) = 0;

virtual bool updateFetchStatus(const QString &tmpPath, const QString &path, qint64 received, bool &canceled,
bool &finished) = 0;
Expand Down Expand Up @@ -272,7 +272,7 @@ class VfsOff : public Vfs {
bool updateMetadata(const QString &, time_t, time_t, qint64, const QByteArray &, QString *) override { return true; }
bool createPlaceholder(const KDC::SyncPath &, const KDC::SyncFileItem &) override { return true; }
bool dehydratePlaceholder(const QString &) override { return true; }
bool convertToPlaceholder(const QString &, const KDC::SyncFileItem &, bool &) override { return true; }
bool convertToPlaceholder(const QString &, const KDC::SyncFileItem &) override { return true; }
bool updateFetchStatus(const QString &, const QString &, qint64, bool &, bool &) override { return true; }
bool forceStatus(const QString &path, bool isSyncing, int progress, bool isHydrated = false) override;

Expand Down
557 changes: 321 additions & 236 deletions src/libsyncengine/propagation/executor/executorworker.cpp

Large diffs are not rendered by default.

78 changes: 60 additions & 18 deletions src/libsyncengine/propagation/executor/executorworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,26 @@ class ExecutorWorker : public OperationProcessor {
void executorCallback(UniqueId jobId);

protected:
/// @note _executorExitCode and _executorExitCause must be set when the function returns
void execute() override;

private:
void initProgressManager();
bool initSyncFileItem(SyncOpPtr syncOp, SyncFileItem &syncItem);
/// @note _executorExitCode and _executorExitCause must be set when the function returns with hasError == true
void handleCreateOp(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> &job, bool &hasError, bool &ignored);

void handleCreateOp(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> &job, bool &hasError);
void checkAlreadyExcluded(const SyncPath &absolutePath, const NodeId &parentId);
/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool checkAlreadyExcluded(const SyncPath &absolutePath, const NodeId &parentId);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool generateCreateJob(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> &job) noexcept;

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool checkLiteSyncInfoForCreate(SyncOpPtr syncOp, const SyncPath &path, bool &isDehydratedPlaceholder);
bool createPlaceholder(const SyncPath &relativeLocalPath);
bool convertToPlaceholder(const SyncPath &relativeLocalPath, bool hydrated, bool &needRestart);

void handleEditOp(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> &job, bool &hasError);
/// @note _executorExitCode and _executorExitCause must be set when the function returns with hasError == true
void handleEditOp(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> &job, bool &hasError, bool &ignored);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool generateEditJob(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> &job);

/**
Expand All @@ -85,42 +91,75 @@ class ExecutorWorker : public OperationProcessor {
* @param syncOp : the operation to propagate.
* @param absolutePath : absolute local path of the affected file.
* @return `true` if the date is modified successfully.
* @note _executorExitCode and _executorExitCause must be set when the function returns false
*/
bool fixModificationDate(SyncOpPtr syncOp, const SyncPath &absolutePath);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool checkLiteSyncInfoForEdit(SyncOpPtr syncOp, const SyncPath &absolutePath, bool &ignoreItem,
bool &isSyncing); // TODO : is called "check..." but perform some actions. Wording not
// good, function probably does too much

void handleMoveOp(SyncOpPtr syncOp, bool &hasError);
bool generateMoveJob(SyncOpPtr syncOp);
/// @note _executorExitCode and _executorExitCause must be set when the function returns with hasError == true
void handleMoveOp(SyncOpPtr syncOp, bool &hasError, bool &ignored, bool &bypassProgressComplete);

void handleDeleteOp(SyncOpPtr syncOp, bool &hasError);
bool generateDeleteJob(SyncOpPtr syncOp);
/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool generateMoveJob(SyncOpPtr syncOp, bool &ignored, bool &bypassProgressComplete);

bool hasRight(SyncOpPtr syncOp, bool &exists);
bool enoughLocalSpace(SyncOpPtr syncOp);
/// @note _executorExitCode and _executorExitCause must be set when the function returns with hasError == true
void handleDeleteOp(SyncOpPtr syncOp, bool &hasError, bool &ignored, bool &bypassProgressComplete);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool generateDeleteJob(SyncOpPtr syncOp, bool &ignored, bool &bypassProgressComplete);

/// @note _executorExitCode and _executorExitCause must be set when the function returns with hasError == true
void waitForAllJobsToFinish(bool &hasError);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool deleteFinishedAsyncJobs();

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool handleManagedBackError(ExitCause jobExitCause, SyncOpPtr syncOp, bool isInconsistencyIssue, bool downloadImpossible);
bool handleFinishedJob(std::shared_ptr<AbstractJob> job, SyncOpPtr syncOp, const SyncPath &relativeLocalPath);
void handleForbiddenAction(SyncOpPtr syncOp, const SyncPath &relativeLocalPath);
void sendProgress();

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool handleFinishedJob(std::shared_ptr<AbstractJob> job, SyncOpPtr syncOp, const SyncPath &relativeLocalPath,
bool &ignored, bool &bypassProgressComplete);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool propagateConflictToDbAndTree(SyncOpPtr syncOp, bool &propagateChange);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool propagateChangeToDbAndTree(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> job, std::shared_ptr<Node> &node);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool propagateCreateToDbAndTree(SyncOpPtr syncOp, const NodeId &newNodeId, std::optional<SyncTime> newLastModTime,
std::shared_ptr<Node> &node);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool propagateEditToDbAndTree(SyncOpPtr syncOp, const NodeId &newNodeId, std::optional<SyncTime> newLastModTime,
std::shared_ptr<Node> &node);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool propagateMoveToDbAndTree(SyncOpPtr syncOp);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool propagateDeleteToDbAndTree(SyncOpPtr syncOp);

/// @note _executorExitCode and _executorExitCause must be set when the function returns false
bool deleteFromDb(std::shared_ptr<Node> node);

bool runCreateDirJob(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> job);
ExitCode createPlaceholder(const SyncPath &relativeLocalPath, ExitCause &exitCause);
ExitCode convertToPlaceholder(const SyncPath &relativeLocalPath, bool hydrated, ExitCause &exitCause);
ExitCode processCreateOrConvertToPlaceholderError(const SyncPath &relativeLocalPath, bool create, ExitCause &exitCause);

void initProgressManager();
bool initSyncFileItem(SyncOpPtr syncOp, SyncFileItem &syncItem);
void handleForbiddenAction(SyncOpPtr syncOp, const SyncPath &relativeLocalPath, bool &ignored);
void sendProgress();
bool hasRight(SyncOpPtr syncOp, bool &exists);
bool enoughLocalSpace(SyncOpPtr syncOp);
bool runCreateDirJob(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> job);
void cancelAllOngoingJobs(bool reschedule = false);

void manageJobDependencies(SyncOpPtr syncOp, std::shared_ptr<AbstractJob> job);

inline bool isLiteSyncActivated() { return _syncPal->vfsMode() != VirtualFileMode::Off; }
Expand All @@ -137,6 +176,8 @@ class ExecutorWorker : public OperationProcessor {
bool getFileSize(const SyncPath &path, uint64_t &size);
void logCorrespondingNodeErrorMsg(const SyncOpPtr syncOp);

void setProgressComplete(const SyncOpPtr syncOp, SyncFileStatus status);

std::unordered_map<UniqueId, std::shared_ptr<AbstractJob>> _ongoingJobs;
TerminatedJobsQueue _terminatedJobs;
std::unordered_map<UniqueId, SyncOpPtr> _jobToSyncOpMap;
Expand All @@ -151,6 +192,7 @@ class ExecutorWorker : public OperationProcessor {
bool _snapshotToInvalidate = false;

friend class TestExecutorWorker;
friend class TestWorkers;
};

} // namespace KDC
12 changes: 8 additions & 4 deletions src/libsyncengine/syncpal/syncpal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ bool SyncPal::vfsPinState(const SyncPath &itemPath, PinState &pinState) {
}

bool SyncPal::vfsSetPinState(const SyncPath &itemPath, PinState pinState) {
if (!_vfsPinState) {
if (!_vfsSetPinState) {
return false;
}

Expand All @@ -405,12 +405,12 @@ bool SyncPal::vfsCreatePlaceholder(const SyncPath &relativeLocalPath, const Sync
return _vfsCreatePlaceholder(syncDbId(), relativeLocalPath, item);
}

bool SyncPal::vfsConvertToPlaceholder(const SyncPath &path, const SyncFileItem &item, bool &needRestart) {
bool SyncPal::vfsConvertToPlaceholder(const SyncPath &path, const SyncFileItem &item) {
if (!_vfsConvertToPlaceholder) {
return false;
}

return _vfsConvertToPlaceholder(syncDbId(), path, item, needRestart);
return _vfsConvertToPlaceholder(syncDbId(), path, item);
}

bool SyncPal::vfsUpdateMetadata(const SyncPath &path, const SyncTime &creationTime, const SyncTime &modtime, const int64_t size,
Expand Down Expand Up @@ -998,6 +998,10 @@ std::shared_ptr<UpdateTree> SyncPal::updateTree(ReplicaSide side) const {
return (side == ReplicaSide::Local ? _localUpdateTree : _remoteUpdateTree);
}

void SyncPal::createProgressInfo() {
_progressInfo = std::shared_ptr<ProgressInfo>(new ProgressInfo(shared_from_this()));
}

ExitCode SyncPal::fileRemoteIdFromLocalPath(const SyncPath &path, NodeId &nodeId) const {
DbNodeId dbNodeId = -1;
bool found = false;
Expand Down Expand Up @@ -1176,7 +1180,7 @@ void SyncPal::start() {
SyncNodeCache::instance()->update(syncDbId(), SyncNodeType::TmpLocalBlacklist, std::unordered_set<NodeId>());

// Create ProgressInfo
_progressInfo = std::shared_ptr<ProgressInfo>(new ProgressInfo(shared_from_this()));
createProgressInfo();

// Create workers
createWorkers();
Expand Down
9 changes: 5 additions & 4 deletions src/libsyncengine/syncpal/syncpal.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SYNCENGINE_EXPORT SyncPal : public std::enable_shared_from_this<SyncPal> {
_vfsCreatePlaceholder = vfsCreatePlaceholder;
}
inline void setVfsConvertToPlaceholderCallback(bool (*vfsConvertToPlaceholder)(int, const SyncPath &,
const SyncFileItem &, bool &)) {
const SyncFileItem &)) {
_vfsConvertToPlaceholder = vfsConvertToPlaceholder;
}
inline void setVfsUpdateMetadataCallback(bool (*vfsUpdateMetadata)(int, const SyncPath &, const SyncTime &,
Expand Down Expand Up @@ -217,7 +217,7 @@ class SYNCENGINE_EXPORT SyncPal : public std::enable_shared_from_this<SyncPal> {
bool vfsSetPinState(const SyncPath &itemPath, PinState pinState);
bool vfsStatus(const SyncPath &itemPath, bool &isPlaceholder, bool &isHydrated, bool &isSyncing, int &progress);
bool vfsCreatePlaceholder(const SyncPath &relativeLocalPath, const SyncFileItem &item);
bool vfsConvertToPlaceholder(const SyncPath &path, const SyncFileItem &item, bool &needRestart);
bool vfsConvertToPlaceholder(const SyncPath &path, const SyncFileItem &item);
bool vfsUpdateMetadata(const SyncPath &path, const SyncTime &creationTime, const SyncTime &modtime, const int64_t size,
const NodeId &id, std::string &error);
bool vfsUpdateFetchStatus(const SyncPath &tmpPath, const SyncPath &path, int64_t received, bool &canceled,
Expand Down Expand Up @@ -287,8 +287,7 @@ class SYNCENGINE_EXPORT SyncPal : public std::enable_shared_from_this<SyncPal> {
bool (*_vfsStatus)(int syncDbId, const SyncPath &itemPath, bool &isPlaceholder, bool &isHydrated, bool &isSyncing,
int &progress){nullptr};
bool (*_vfsCreatePlaceholder)(int syncDbId, const SyncPath &relativeLocalPath, const SyncFileItem &item){nullptr};
bool (*_vfsConvertToPlaceholder)(int syncDbId, const SyncPath &path, const SyncFileItem &item,
bool &needRestart){nullptr};
bool (*_vfsConvertToPlaceholder)(int syncDbId, const SyncPath &path, const SyncFileItem &item){nullptr};
bool (*_vfsUpdateMetadata)(int syncDbId, const SyncPath &path, const SyncTime &creationTime, const SyncTime &modtime,
const int64_t size, const NodeId &id, std::string &error){nullptr};
bool (*_vfsUpdateFetchStatus)(int syncDbId, const SyncPath &tmpPath, const SyncPath &path, int64_t received,
Expand Down Expand Up @@ -354,6 +353,7 @@ class SYNCENGINE_EXPORT SyncPal : public std::enable_shared_from_this<SyncPal> {
std::shared_ptr<UpdateTree> updateTree(ReplicaSide side) const;

// Progress info management
void createProgressInfo();
void resetEstimateUpdates();
void startEstimateUpdates();
void stopEstimateUpdates();
Expand Down Expand Up @@ -400,6 +400,7 @@ class SYNCENGINE_EXPORT SyncPal : public std::enable_shared_from_this<SyncPal> {
friend class TestSnapshot;
friend class TestLocalJobs;
friend class TestIntegration;
friend class TestWorkers;
};

} // namespace KDC
Original file line number Diff line number Diff line change
Expand Up @@ -488,22 +488,21 @@ bool Snapshot::checkIntegrityRecursively() {

bool Snapshot::checkIntegrityRecursively(const NodeId &parentId) {
// Check that we do not have the same file twice in the same folder
const auto &parrentItem = _items[parentId];
for (auto child = parrentItem.childrenIds().begin(), end = parrentItem.childrenIds().end(); child != end; child++) {
if (!checkIntegrityRecursively(*child)) {
const auto &parentItem = _items[parentId];
std::set<SyncName> names;
for (auto childId = parentItem.childrenIds().begin(), end = parentItem.childrenIds().end(); childId != end; childId++) {
if (!checkIntegrityRecursively(*childId)) {
return false;
}

for (auto child2 = child; child2 != end; ++child2) {
if (*child != *child2 && _items[*child].name() == _items[*child2].name()) {
LOG_ERROR(Log::instance()->getLogger(), "Snapshot integrity check failed, the folder named: \""
<< SyncName2Str(parrentItem.name()).c_str() << "\"("
<< parrentItem.id().c_str() << ") contains: \""
<< SyncName2Str(_items[*child].name()).c_str()
<< "\" twice with two differents NodeId (" << child->c_str()
<< " and " << child2->c_str() << ")");
return false;
}
auto result = names.insert(_items[*childId].name());
if (!result.second) {
LOGW_WARN(Log::instance()->getLogger(), L"Snapshot integrity check failed, the folder named: \""
<< SyncName2WStr(parentItem.name()).c_str() << L"\"("
<< Utility::s2ws(parentItem.id()).c_str() << L") contains: \""
<< SyncName2WStr(_items[*childId].name()).c_str()
<< L"\" twice with two differents NodeId");
return false;
}
}
return true;
Expand Down
11 changes: 4 additions & 7 deletions src/server/appserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2425,18 +2425,15 @@ bool AppServer::vfsCreatePlaceholder(int syncDbId, const SyncPath &relativeLocal
return true;
}

bool AppServer::vfsConvertToPlaceholder(int syncDbId, const SyncPath &path, const SyncFileItem &item, bool &needRestart) {
bool AppServer::vfsConvertToPlaceholder(int syncDbId, const SyncPath &path, const SyncFileItem &item) {
if (_vfsMap.find(syncDbId) == _vfsMap.end()) {
LOG_WARN(Log::instance()->getLogger(), "Vfs not found in vfsMap for syncDbId=" << syncDbId);
return false;
}

if (!_vfsMap[syncDbId]->convertToPlaceholder(SyncName2QStr(path.native()), item, needRestart)) {
if (!needRestart) {
LOGW_WARN(Log::instance()->getLogger(), L"Error in Vfs::convertToPlaceholder for syncDbId="
<< syncDbId << L" and path=" << Path2WStr(item.path()).c_str());
}

if (!_vfsMap[syncDbId]->convertToPlaceholder(SyncName2QStr(path.native()), item)) {
LOGW_WARN(Log::instance()->getLogger(), L"Error in Vfs::convertToPlaceholder for syncDbId="
<< syncDbId << L" and path=" << Path2WStr(item.path()).c_str());
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/appserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class AppServer : public SharedTools::QtSingleApplication {
static bool vfsStatus(int syncDbId, const SyncPath &itemPath, bool &isPlaceholder, bool &isHydrated, bool &isSyncing,
int &progress);
static bool vfsCreatePlaceholder(int syncDbIdconst, const SyncPath &relativeLocalPath, const SyncFileItem &item);
static bool vfsConvertToPlaceholder(int syncDbId, const SyncPath &path, const SyncFileItem &item, bool &needRestart);
static bool vfsConvertToPlaceholder(int syncDbId, const SyncPath &path, const SyncFileItem &item);
static bool vfsUpdateMetadata(int syncDbId, const SyncPath &path, const SyncTime &creationTime, const SyncTime &modtime,
const int64_t size, const NodeId &id, std::string &error);
static bool vfsUpdateFetchStatus(int syncDbId, const SyncPath &tmpPath, const SyncPath &path, int64_t received,
Expand Down
Loading

0 comments on commit 0ce82aa

Please sign in to comment.