Skip to content

Commit

Permalink
Merge branch 'develop' into fix-formatting-issue-in-executor
Browse files Browse the repository at this point in the history
  • Loading branch information
herve-er authored Dec 19, 2024
2 parents ae90edc + 6ec3a1e commit c210fdd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/libcommonserver/utility/utility_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "log/log.h"
#include "libcommon/utility/utility.h"
#include "libcommonserver/utility/utility.h"

#include <sstream>
#include <string>
Expand All @@ -39,7 +40,7 @@ static bool init_private() {

static void makeMessage() {}

bool moveItemToTrash(const SyncPath &itemPath, std::string &errorStr);
bool moveItemToTrash(const SyncPath &itemPath, std::wstring &errorStr);
bool preventSleeping(bool enable);
bool preventSleeping();
void restartFinderExtension();
Expand All @@ -50,9 +51,10 @@ static bool moveItemToTrash_private(const SyncPath &itemPath) {
return false;
}

std::string errorStr;
std::wstring errorStr;
if (!moveItemToTrash(itemPath, errorStr)) {
LOG_WARN(Log::instance()->getLogger(), "Error in moveItemToTrash - err=" << errorStr.c_str());
LOGW_WARN(Log::instance()->getLogger(),
L"Error in moveItemToTrash on " << Utility::formatSyncPath(itemPath) << L" - err='" << errorStr << L"'.");
return false;
}

Expand Down
12 changes: 10 additions & 2 deletions src/libcommonserver/utility/utility_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@

namespace KDC {

bool moveItemToTrash(const SyncPath &itemPath, std::string &errorStr) {
bool moveItemToTrash(const SyncPath &itemPath, std::wstring &errorStr)
{
NSString *filePath = [NSString stringWithCString:itemPath.c_str() encoding:NSUTF8StringEncoding];

if (filePath == nullptr) {
errorStr = L"Error in stringWithCString. Failed to cast std filepath to NSString.";
return false;
}
NSURL *fileURL = [NSURL fileURLWithPath:filePath];

NSFileManager *fileManager = [NSFileManager defaultManager];
Expand All @@ -37,7 +43,9 @@ bool moveItemToTrash(const SyncPath &itemPath, std::string &errorStr) {
BOOL success = [fileManager trashItemAtURL:fileURL resultingItemURL:nil error:&error];

if (error != nil) {
errorStr = std::string([error.localizedDescription UTF8String]);
const auto wcharError = reinterpret_cast<const wchar_t *>(
[error.localizedDescription cStringUsingEncoding:NSUTF32LittleEndianStringEncoding]);
errorStr = std::wstring(wcharError);
}

return success;
Expand Down

0 comments on commit c210fdd

Please sign in to comment.