Skip to content

Commit

Permalink
Merge branch 'fix/dont-use-disk-arbitration-for-ios' into 'develop'
Browse files Browse the repository at this point in the history
SDK-3419: Fix compilation issue for iOS

See merge request sdk/sdk!5087
  • Loading branch information
dwmega committed Nov 23, 2023
2 parents 8689546 + 5a66f2a commit f785f5b
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 132 deletions.
16 changes: 11 additions & 5 deletions include/mega/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,7 @@ class MEGA_API LocalPath
friend void AddHiddenFileAttribute(LocalPath& path);
friend class GfxProviderFreeImage;
friend struct FileSystemAccess;
#ifdef USE_IOS
friend const string adjustBasePath(const LocalPath& name);
#else
friend const string& adjustBasePath(const LocalPath& name);
#endif

friend int compareUtf(const string&, bool unescaping1, const string&, bool unescaping2, bool caseInsensitive);
friend int compareUtf(const string&, bool unescaping1, const LocalPath&, bool unescaping2, bool caseInsensitive);
friend int compareUtf(const LocalPath&, bool unescaping1, const string&, bool unescaping2, bool caseInsensitive);
Expand Down Expand Up @@ -338,6 +334,16 @@ class MEGA_API LocalPath
bool operator==(const LocalPath& p) const { return localpath == p.localpath; }
bool operator!=(const LocalPath& p) const { return localpath != p.localpath; }
bool operator<(const LocalPath& p) const { return localpath < p.localpath; }

// Try to avoid using this function as much as you can.
//
// It's present for efficiency reasons and is really only meant for
// specific cases when we are using a LocalPath instance in a system
// call.
const string_type& rawValue() const
{
return localpath;
}
};

inline std::ostream& operator<<(std::ostream& os, const LocalPath& p)
Expand Down
14 changes: 10 additions & 4 deletions include/mega/posix/megafs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
#define DEBRISFOLDER ".debris"

namespace mega {

namespace detail {

using AdjustBasePathResult =
IOS_OR_POSIX(std::string, const std::string&);

AdjustBasePathResult adjustBasePath(const LocalPath& path);

} // detail

struct MEGA_API PosixDirAccess : public DirAccess
{
DIR* dp;
Expand All @@ -66,10 +76,6 @@ class MEGA_API PosixFileSystemAccess : public FileSystemAccess
public:
using FileSystemAccess::getlocalfstype;

#ifdef USE_IOS
static char *appbasepath;
#endif

int defaultfilepermissions;
int defaultfolderpermissions;

Expand Down
13 changes: 13 additions & 0 deletions include/mega/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1480,4 +1480,17 @@ class CheckableMutex<T, true>

using detail::CheckableMutex;

// For convenience.
#ifdef USE_IOS

#define IOS_ONLY(i) i
#define IOS_OR_POSIX(i, p) i

#else // USE_IOS

#define IOS_ONLY(i)
#define IOS_OR_POSIX(i, p) p

#endif // ! USE_IOS

#endif
25 changes: 14 additions & 11 deletions src/gfx/GfxProcCG.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@
return NULL;
}

bool GfxProviderCG::readbitmap(FileSystemAccess* fa, const LocalPath& name, int size) {
string absolutename;
NSString *sourcePath;
if (PosixFileSystemAccess::appbasepath && !name.beginsWithSeparator()) {
absolutename = PosixFileSystemAccess::appbasepath;
absolutename.append(name.platformEncoded());
sourcePath = [NSString stringWithCString:absolutename.c_str() encoding:[NSString defaultCStringEncoding]];
} else {
sourcePath = [NSString stringWithCString:name.platformEncoded().c_str() encoding:[NSString defaultCStringEncoding]];
}

bool GfxProviderCG::readbitmap(FileSystemAccess* fa, const LocalPath& path, int size) {
// Convenience.
using mega::detail::AdjustBasePathResult;
using mega::detail::adjustBasePath;

// Ensure provided path is absolute.
AdjustBasePathResult absolutePath = adjustBasePath(path);

// Make absolute path usable to Cocoa.
NSString* sourcePath =
[NSString stringWithCString: absolutePath.c_str()
encoding: [NSString defaultCStringEncoding]];

// Couldn't create a Cocoa-friendly path.
if (sourcePath == nil) {
return false;
}
Expand Down
48 changes: 35 additions & 13 deletions src/osx/fs.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include <sys/mount.h>
#include <sys/param.h>

#include <DiskArbitration/DADisk.h>

#include <cassert>
#include <future>

#include "mega.h"

// Disk Arbitration is not available on iOS.
#ifndef USE_IOS
# include <DiskArbitration/DADisk.h>
#endif // ! USE_IOS

namespace mega {

// Convenience.
Expand Down Expand Up @@ -117,7 +120,13 @@ static DeviceOfResult deviceOf(const std::string& path)
return result;
}

static std::string uuidOf(const std::string& device)
// Convenience.
using UUIDOfResult =
std::pair<std::string, bool>;

#ifndef USE_IOS

static UUIDOfResult uuidOf(const std::string& device)
{
// Convenience.
using DictionaryPtr = CFPtr<CFDictionaryRef>;
Expand All @@ -132,7 +141,7 @@ static std::string uuidOf(const std::string& device)

// Couldn't establish DA session.
if (!session)
return std::string();
return UUIDOfResult("", false);

// Try and get a reference to the specified device.
DiskPtr disk(DADiskCreateFromBSDName(allocator,
Expand All @@ -141,14 +150,14 @@ static std::string uuidOf(const std::string& device)

// Couldn't get a reference to the device.
if (!disk)
return std::string();
return UUIDOfResult("", false);

// Try and get the device's description.
DictionaryPtr info(DADiskCopyDescription(disk.get()));

// Couldn't get device's description.
if (!info)
return std::string();
return UUIDOfResult("", false);

// What UUIDs do we want to retrieve?
static const std::vector<const char*> names = {
Expand All @@ -172,7 +181,7 @@ static std::string uuidOf(const std::string& device)

// Couldn't create key.
if (!key)
return std::string();
return UUIDOfResult("", false);

// Try and retrieve UUID associated with key.
auto uuid = ([&]() {
Expand All @@ -196,7 +205,7 @@ static std::string uuidOf(const std::string& device)

// Try and retrieve the string's raw value.
if (auto* value = CFStringGetCStringPtr(string.get(), encoding))
return value;
return UUIDOfResult(value, true);

// Compute necessary buffer length.
auto required =
Expand All @@ -223,16 +232,29 @@ static std::string uuidOf(const std::string& device)
buffer.resize(static_cast<std::size_t>(required));

// Return UUID to caller.
return buffer;
return UUIDOfResult(std::move(buffer), true);
}

// Couldn't retrieve UUID.
return std::string();
return UUIDOfResult("", false);
}

#else // ! USE_IOS

static UUIDOfResult uuidOf(const std::string&)
{
return UUIDOfResult("", true);
}

#endif // USE_IOS

fsfp_t FileSystemAccess::fsFingerprint(const LocalPath& path) const
{
auto device = deviceOf(path.localpath);
// Convenience.
using detail::adjustBasePath;

// What device contains path?
auto device = deviceOf(adjustBasePath(path));

// Couldn't determine which device contains path.
if (device.first.empty())
Expand All @@ -242,11 +264,11 @@ fsfp_t FileSystemAccess::fsFingerprint(const LocalPath& path) const
auto uuid = uuidOf(device.first);

// Couldn't determine UUID.
if (uuid.empty())
if (!uuid.second)
return fsfp_t();

// Return fingerprint to caller.
return fsfp_t(device.second, std::move(uuid));
return fsfp_t(device.second, std::move(uuid.first));
}

MacFileSystemAccess::MacFileSystemAccess()
Expand Down
Loading

0 comments on commit f785f5b

Please sign in to comment.