Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class NodeScriptRuntime : public OMClass<NodeScriptRuntime, IScriptRuntime, IScr
int m_instanceId;
std::string m_name;
std::string m_resourceName;
std::string m_resourceMountPrefix;
std::string m_tempDir;
bool m_isMonitorRuntime = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ const std::string_view& resource)

if (!device.GetRef())
{
std::string absolutePath = std::filesystem::absolute(std::filesystem::path(path)).string();
device = vfs::FindDevice(absolutePath, path);
std::error_code ec;
const std::filesystem::path absolutePath = std::filesystem::absolute(std::filesystem::path(path), ec);
device = vfs::FindDevice(ec ? path : absolutePath.string(), path, m_resourceMountPrefix);
if (!device.GetRef())
{
trace("Filesystem permission check from '%s' for permission %s on resource '%s' - no device found\n", m_resourceName.c_str(), permName.c_str(), res.c_str());
Expand Down Expand Up @@ -387,6 +388,7 @@ result_t NodeScriptRuntime::Create(IScriptHost* host)
char* resourceName = nullptr;
m_resourceHost->GetResourceName(&resourceName);
m_resourceName = resourceName;
m_resourceMountPrefix = "@" + m_resourceName + "/";

// don't create the runtime environment if nodejs is not initialized
if (!g_nodeEnv.IsInitialized())
Expand Down
12 changes: 9 additions & 3 deletions code/components/vfs-core/include/VFSManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class VFS_CORE_EXPORT Manager : public fwRefCountable

virtual void Unmount(const std::string& path) = 0;

virtual fwRefContainer<Device> GetNativeDevice(void* nativeDevice);
virtual fwRefContainer<Device> GetNativeDevice(void* nativeDevice);

// Used when multiple mounted devices resolve to the same native path.
virtual fwRefContainer<Device> FindDevice(const std::string& absolutePath, std::string& transformedPath, const std::string& preferredMountPrefix);
};

VFS_CORE_EXPORT fwRefContainer<Stream> OpenRead(const std::string& path);
Expand All @@ -54,8 +57,11 @@ VFS_CORE_EXPORT fwRefContainer<Stream> Create(const std::string& path, bool crea

VFS_CORE_EXPORT fwRefContainer<Device> GetDevice(const std::string& path);

VFS_CORE_EXPORT fwRefContainer<Device> FindDevice(const std::string& absolutePath, std::string& transformedPath);

VFS_CORE_EXPORT fwRefContainer<Device> FindDevice(const std::string& absolutePath, std::string& transformedPath);

// Used when multiple mounted devices resolve to the same native path.
VFS_CORE_EXPORT fwRefContainer<Device> FindDevice(const std::string& absolutePath, std::string& transformedPath, const std::string& preferredMountPrefix);

VFS_CORE_EXPORT fwRefContainer<Device> GetNativeDevice(void* nativeDevice);

VFS_CORE_EXPORT void Mount(fwRefContainer<Device> device, const std::string& path);
Expand Down
10 changes: 10 additions & 0 deletions code/components/vfs-core/src/VFSManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ fwRefContainer<Device> Manager::GetNativeDevice(void* nativeDevice)
return nullptr;
}

fwRefContainer<Device> Manager::FindDevice(const std::string& absolutePath, std::string& transformedPath, const std::string&)
{
return FindDevice(absolutePath, transformedPath);
}

fwRefContainer<Stream> OpenRead(const std::string& path)
{
return Instance<Manager>::Get()->OpenRead(path);
Expand Down Expand Up @@ -125,6 +130,11 @@ fwRefContainer<Device> FindDevice(const std::string& absolutePath, std::string&
return Instance<Manager>::Get()->FindDevice(absolutePath, transformedPath);
}

fwRefContainer<Device> FindDevice(const std::string& absolutePath, std::string& transformedPath, const std::string& preferredMountPrefix)
{
return Instance<Manager>::Get()->FindDevice(absolutePath, transformedPath, preferredMountPrefix);
}

fwRefContainer<Device> GetNativeDevice(void* nativeDevice)
{
return Instance<Manager>::Get()->GetNativeDevice(nativeDevice);
Expand Down
14 changes: 13 additions & 1 deletion code/components/vfs-impl-server/include/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ namespace vfs
class ManagerServer : public vfs::Manager
{
private:
struct MountedDevice
{
fwRefContainer<Device> device;
std::string absolutePath;
std::string canonicalPath;
bool resolvesThroughLink = false;
};

struct MountPoint
{
std::string prefix;

mutable std::vector<fwRefContainer<Device>> devices; // mutable? MUTABLE? is this Rust?!
mutable std::vector<MountedDevice> devices; // mutable? MUTABLE? is this Rust?!
};

// sorts mount points based on longest prefix
Expand All @@ -37,6 +45,8 @@ class ManagerServer : public vfs::Manager

std::recursive_mutex m_mountMutex;

bool m_hasCanonicalPathMounts = false;

// fallback device - usually a local file system implementation
fwRefContainer<vfs::Device> m_fallbackDevice;

Expand All @@ -50,6 +60,8 @@ class ManagerServer : public vfs::Manager

virtual fwRefContainer<Device> GetNativeDevice(void* nativeDevice) override;

virtual fwRefContainer<Device> FindDevice(const std::string& absolutePath, std::string& transformedPath, const std::string& preferredMountPrefix) override;

virtual void Mount(fwRefContainer<Device> device, const std::string& path) override;

virtual void Unmount(const std::string& path) override;
Expand Down
Loading
Loading