Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kdesktop 1354 mac os a file can be dehydrated during its upload #413

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/libcommonserver/io/iohelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,21 @@ struct IoHelper {
*/
static bool setXAttrValue(const SyncPath &path, const std::string &attrName, const std::string &value,
IoError &ioError) noexcept;
//! Remove the extended attributes with specified names for the item indicated by path.
/*!
\param path is the file system path of the item.
\param attrNames is a vector of the names of the extended attributes to remove.
\param ioError holds the error returned when an underlying OS API call fails.
\return true if no unexpected error occurred, false otherwise.
*/
static bool removeXAttrs(const SyncPath &path, const std::vector<std::string> &attrNames, IoError &ioError) noexcept;
//! Remove the LiteSync extended attributes for the item indicated by path.
/*!
\param path is the file system path of the item.
\param ioError holds the error returned when an underlying OS API call fails.
\return true if no unexpected error occurred, false otherwise.
*/
static bool removeLiteSyncXAttrs(const SyncPath &path, IoError &ioError) noexcept;
#endif

#ifdef _WIN32
Expand Down
29 changes: 24 additions & 5 deletions src/libcommonserver/io/iohelper_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

namespace KDC {

static constexpr std::string_view EXT_ATTR_STATUS("com.infomaniak.drive.desktopclient.litesync.status");
static constexpr std::string_view EXT_ATTR_PIN_STATE("com.infomaniak.drive.desktopclient.litesync.pinstate");

namespace {
inline bool _isXAttrValueExpectedError(IoError error) {
return (error == IoError::NoSuchFileOrDirectory) || (error == IoError::AttrNotFound) || (error == IoError::AccessDenied);
Expand All @@ -40,7 +43,7 @@ bool IoHelper::getXAttrValue(const SyncPath &path, const std::string &attrName,
value = "";
ItemType itemType;
if (!getItemType(path, itemType)) {
LOGW_WARN(logger(), L"Error in IoHelper::getItemType for " << Utility::formatIoError(path, itemType.ioError).c_str());
LOGW_WARN(logger(), L"Error in IoHelper::getItemType for " << Utility::formatIoError(path, itemType.ioError));
ioError = itemType.ioError;
return false;
}
Expand Down Expand Up @@ -82,7 +85,7 @@ bool IoHelper::setXAttrValue(const SyncPath &path, const std::string &attrName,
IoError &ioError) noexcept {
ItemType itemType;
if (!getItemType(path, itemType)) {
LOGW_WARN(logger(), L"Error in IoHelper::getItemType for " << Utility::formatIoError(path, itemType.ioError).c_str());
LOGW_WARN(logger(), L"Error in IoHelper::getItemType for " << Utility::formatIoError(path, itemType.ioError));
ioError = itemType.ioError;
return false;
}
Expand All @@ -105,14 +108,30 @@ bool IoHelper::setXAttrValue(const SyncPath &path, const std::string &attrName,
return true;
}

bool IoHelper::removeXAttrs(const SyncPath &path, const std::vector<std::string> &attrNames, IoError &ioError) noexcept {
for (const auto &attrName: attrNames) {
if (removexattr(path.native().c_str(), attrName.c_str(), XATTR_NOFOLLOW) == -1) {
luc-guyot-infomaniak marked this conversation as resolved.
Show resolved Hide resolved
ioError = posixError2ioError(errno);
return _isXAttrValueExpectedError(ioError);
}
}

// XAttr has been removed
ioError = IoError::Success;
return true;
}

bool IoHelper::removeLiteSyncXAttrs(const SyncPath &path, IoError &ioError) noexcept {
const std::vector<std::string> liteSyncAttrName = {std::string(EXT_ATTR_STATUS), std::string(EXT_ATTR_PIN_STATE)};
return removeXAttrs(path, liteSyncAttrName, ioError);
}

bool IoHelper::checkIfFileIsDehydrated(const SyncPath &itemPath, bool &isDehydrated, IoError &ioError) noexcept {
isDehydrated = false;
ioError = IoError::Success;

static const std::string EXT_ATTR_STATUS = "com.infomaniak.drive.desktopclient.litesync.status";

std::string value;
const bool result = IoHelper::getXAttrValue(itemPath.native(), EXT_ATTR_STATUS, value, ioError);
const bool result = IoHelper::getXAttrValue(itemPath.native(), std::string(EXT_ATTR_STATUS), value, ioError);
if (!result) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/libsyncengine/propagation/executor/executorworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,14 @@ ExitInfo ExecutorWorker::generateCreateJob(SyncOpPtr syncOp, std::shared_ptr<Abs
return ExitCode::DataError;
}
} else {
#ifdef _WIN32
// Don't do this on macOS as status and pin state are set at the end of the upload
if (ExitInfo exitInfo = convertToPlaceholder(relativeLocalFilePath, true); !exitInfo) {
LOGW_SYNCPAL_WARN(_logger,
L"Failed to convert to placeholder for: " << SyncName2WStr(syncOp->affectedNode()->name()));
return exitInfo;
}
#endif

uint64_t filesize = 0;
if (ExitInfo exitInfo = getFileSize(absoluteLocalFilePath, filesize); !exitInfo) {
Expand Down
Loading
Loading