-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[WasmFS] Fix absolute path access under NODERAWFS #24733
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
a6e22e4
f04892c
cb9bb3e
11233e0
2dd31f5
e21bc63
fa12429
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,9 @@ class NodeState { | |
| int fd = -1; | ||
|
|
||
| public: | ||
| // Base path in the host filesystem for this backend. | ||
| // An empty string means "no base path": paths are used as-is without | ||
| // prefixing. | ||
| std::string path; | ||
|
|
||
| NodeState(std::string path) : path(path) {} | ||
|
|
@@ -180,6 +183,11 @@ class NodeDirectory : public Directory { | |
|
|
||
| private: | ||
| std::string getChildPath(const std::string& name) { | ||
| // If state.path is empty, this backend represents the real root and paths | ||
| // should be passed through unchanged. | ||
| if (state.path.empty()) { | ||
| return name; | ||
| } | ||
| return state.path + '/' + name; | ||
| } | ||
|
|
||
|
|
@@ -296,6 +304,10 @@ class NodeBackend : public Backend { | |
| std::shared_ptr<Symlink> createSymlink(std::string target) override { | ||
| WASMFS_UNREACHABLE("TODO: implement NodeBackend::createSymlink"); | ||
| } | ||
|
|
||
| virtual bool requiresPathTraversal() override { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about calling this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds good to me. |
||
| return !mountPath.empty(); | ||
| } | ||
| }; | ||
|
|
||
| // TODO: symlink | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,12 +66,21 @@ ParsedParent doParseParent(std::string_view path, | |
| size_t& recursions) { | ||
| // Empty paths never exist. | ||
| if (path.empty()) { | ||
| return {-ENOENT}; | ||
| return -ENOENT; | ||
| } | ||
|
|
||
| auto root = wasmFS.getRootDirectory(); | ||
|
|
||
| // If the root backend does not require path traversal, it can operate on the | ||
| // full path directly. In that case, skip WasmFS path parsing and pass the | ||
| // path through unchanged. | ||
| if (!root->getBackend()->requiresPathTraversal()) { | ||
| return {std::make_pair(std::move(curr), path)}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to cause WasmFS to model the underlying file system as completely flat, so that there is a single mount directory directly containing every file ever opened, no matter how deep that file is in the underlying directory structure? If so, is that going to cause problems with reading directory entries?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, this is going to break in such situations as it implicitly assumes that the entire file system behaves like the root backend. Commit e21bc63 changes this to $ tree / -L 2 --dirsfirst
/ (MEMFS)
├── dev
│ ├── null -> SpecialFiles::getNull()
│ ├── random -> SpecialFiles::getRandom()
│ ├── stderr -> SpecialFiles::getStderr()
│ ├── stdin -> SpecialFiles::getStdin()
│ ├── stdout -> SpecialFiles::getStdout()
│ └── urandom -> SpecialFiles::getURandom()
├── tmp
└── host (NODERAWFS)(i.e. the Node filesystem is mounted under
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... actually, that's not a great example, since it already worked without issues (AFAIK). I suspect it would have failed previously with the following layout: $ tree / -L 3 --dirsfirst
/ (NODERAWFS)
└── memory (MEMFS)
├── dev
│ ├── null -> SpecialFiles::getNull()
│ ├── random -> SpecialFiles::getRandom()
│ ├── stderr -> SpecialFiles::getStderr()
│ ├── stdin -> SpecialFiles::getStdin()
│ ├── stdout -> SpecialFiles::getStdout()
│ └── urandom -> SpecialFiles::getURandom()
└── tmpSo, the I suppose that we're missing some test coverage for this. |
||
| } | ||
|
|
||
| // Handle absolute paths. | ||
| if (path.front() == '/') { | ||
| curr = wasmFS.getRootDirectory(); | ||
| curr = root; | ||
| path.remove_prefix(1); | ||
| } | ||
|
|
||
|
|
@@ -84,7 +93,7 @@ ParsedParent doParseParent(std::string_view path, | |
| // contain a child segment for us to return. The root is its own parent, so we | ||
| // can handle this by returning (root, "."). | ||
| if (path.empty()) { | ||
| return {std::make_pair(std::move(curr), std::string_view("."))}; | ||
| return {std::make_pair(std::move(curr), ".")}; | ||
| } | ||
|
|
||
| while (true) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.