Closed
Conversation
`std.os.realpathat` is similar to `std.os.realpath`, however, it accepts a tuple `(fd_t, []const u8)` of args and thus works out the realpath of a relative path wrt to some opened file descriptor. If the input pathname argument turns out to be an absolute path, this function reverts to calling `realpath` on that pathname completely ignoring the input file descriptor. This behaviour is standard in POSIX and IMHO a good rule of thumb to follow. If the input file descriptor was obtained using `std.fs.cwd()` call, this function reverts to `std.os.getcwd()` to obtain the file descriptor's path.
This commit adds `std.fs.path.resolveat` functions which is similar to `std.fs.path.resolve`, however, differs in the sense that, in addition to a slice of paths, it also accepts a `Dir` handle with respect to which the paths should be resolved. It also issues one syscall in order to workout the path to the `Dir` handle. With `std.fs.path.resolveat`, it is now possible to store `work_dir` handle directly in `CacheHash` struct and workout paths to cached files wrt to it rather than wrt `cwd`.
`std.fs.path.resolveRelative` function is like `std.fs.path.resolve` however it resolves relative paths **only**, and they are always resolved to wrt ".". If the final path is resolved to "." or beyond, `null` is returned instead to signify this. Also, if an absolute path is passed as an argument, `ResolveRelativeError.AbsolutePath` is thrown. This function is particularly useful for Capsicum-like targets such as WASI. This commit also tweaks `std.cache_hash.CacheHash` to use either `std.fs.path.resolveat` or `std.fs.path.resolveRelative` (the latter used when targeting WASI). This way, we essentially got rid of any mention of CWD, and hence, it is now possible to use `CacheHash` struct in WASI. As a result, all tests in the said module have been enabled for WASI.
Member
Author
|
@andrewrk I'm thinking of breaking up this PR into a couple smaller, or at least extracting the
What do you reckon? |
Member
Author
|
Closing in favour of landing in stages. Part 1 in #5701. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #5437.
Summary of changes to achieve this:
adds
std.os.realpathatwhich is similar tostd.os.realpath, however, it accepts a tuple(fd_t, []const u8)of args and thus works out the realpath of a relative path wrt to some opened file descriptor.If the input pathname argument turns out to be an absolute path, this function reverts to calling
realpathon that pathname completely ignoring the input file descriptor. This behaviour is standard in POSIX and IMHO a good rule of thumb to follow.If the input file descriptor was obtained using
std.fs.cwd()call, this function reverts tostd.os.getcwd()to obtain the file descriptor's path.adds
std.fs.path.resolveatfunctions which is similar tostd.fs.path.resolve, however, differs in the sense that, in addition to a slice of paths, it also accepts aDirhandle with respect to which the paths should be resolved. It also issues one syscall in order to workout the path to theDirhandle.With
std.fs.path.resolveat, it is now possible to storework_dirhandle directly inCacheHashstruct and workout paths to cached files wrt to it rather than wrtcwd.adds
std.fs.path.resolveRelativefunction which is likestd.fs.path.resolvehowever it resolves relative paths only, and they are always resolved to wrt ".". If the final path is resolved to "." or beyond,nullis returned instead to signify this. Also, if an absolute path is passed as an argument,ResolveRelativeError.AbsolutePathis thrown. This function is particularly useful for Capsicum-like targets such as WASI.This commit also tweaks
std.cache_hash.CacheHashto use eitherstd.fs.path.resolveatorstd.fs.path.resolveRelative(the latter used when targeting WASI). This way, we essentially got rid of any mention of CWD, and hence, it is now possible to useCacheHashstruct in WASI. As a result, all tests in the said module have been enabled for WASI.cc @andrewrk, as per usual, looking forward to your thoughts on this!