Skip to content

Commit

Permalink
Addresses Hervé's code review comments: asserts on unset attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-guyot-infomaniak committed Oct 2, 2024
1 parent e7f9dc8 commit 2e4abb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/libsyncengine/syncpal/virtualfilescleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ VirtualFilesCleaner::VirtualFilesCleaner(const SyncPath &path, int syncDbId) :

bool VirtualFilesCleaner::run() {
// Clear xattr on root path
assert(_vfsClearFileAttributes);
_vfsClearFileAttributes(_syncDbId, _rootPath);
return removePlaceholdersRecursivly(_rootPath);
return removePlaceholdersRecursively(_rootPath);
}

bool VirtualFilesCleaner::removePlaceholdersRecursivly(const SyncPath &parentPath) {
bool VirtualFilesCleaner::removePlaceholdersRecursively(const SyncPath &parentPath) {
const SyncName rootPathStr = _rootPath.native();
try {
std::filesystem::recursive_directory_iterator dirIt;
Expand Down Expand Up @@ -91,6 +92,7 @@ bool VirtualFilesCleaner::removePlaceholdersRecursivly(const SyncPath &parentPat
bool isHydrated = false;
bool isSyncing = false;
int progress = 0;
assert(_vfsStatus);
if (!_vfsStatus(_syncDbId, dirIt->path(), isPlaceholder, isHydrated, isSyncing, progress)) {
LOGW_WARN(_logger, L"Error in vfsStatus for path=" << Path2WStr(dirIt->path()).c_str());
_exitCode = ExitCode::SystemError;
Expand Down Expand Up @@ -163,13 +165,15 @@ bool VirtualFilesCleaner::removePlaceholdersRecursivly(const SyncPath &parentPat
}

// Clear xattr
assert(_vfsClearFileAttributes);
_vfsClearFileAttributes(_syncDbId, dirIt->path());
}
} catch (std::filesystem::filesystem_error &e) {
LOG_WARN(_logger, "Error caught in VirtualFilesCleaner::removePlaceholdersRecursivly: " << e.code() << " - " << e.what());
LOG_WARN(_logger,
"Error caught in VirtualFilesCleaner::removePlaceholdersRecursively: " << e.code() << " - " << e.what());
return false;
} catch (...) {
LOG_WARN(_logger, "Error caught in VirtualFilesCleaner::removePlaceholdersRecursivly");
LOG_WARN(_logger, "Error caught in VirtualFilesCleaner::removePlaceholdersRecursively");
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/libsyncengine/syncpal/virtualfilescleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VirtualFilesCleaner {
inline ExitCause exitCause() const { return _exitCause; }

private:
bool removePlaceholdersRecursivly(const SyncPath &parentPath);
bool removePlaceholdersRecursively(const SyncPath &parentPath);
bool recursiveDirectoryIterator(const SyncPath &path, std::filesystem::recursive_directory_iterator &dirIt);
bool folderCanBeProcessed(std::filesystem::recursive_directory_iterator &dirIt);

Expand All @@ -51,8 +51,8 @@ class VirtualFilesCleaner {
int _syncDbId{-1};
std::shared_ptr<SyncDb> _syncDb = nullptr;
bool (*_vfsStatus)(int syncDbId, const SyncPath &itemPath, bool &isPlaceholder, bool &isHydrated, bool &isSyncing,
int &progress){nullptr};
bool (*_vfsClearFileAttributes)(int syncDbId, const SyncPath &itemPath){nullptr};
int &progress) = nullptr;
bool (*_vfsClearFileAttributes)(int syncDbId, const SyncPath &itemPath) = nullptr;

ExitCode _exitCode = ExitCode::Unknown;
ExitCause _exitCause = ExitCause::Unknown;
Expand Down

0 comments on commit 2e4abb8

Please sign in to comment.