feat: implement physical and logical cwd #219
Open
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.
After diving into the system's paths rabbit hole for a while, I've implemented cross-platform
cwd
handling for the shell, along with support forcd -L -P
andpwd -L -P
.Closes: #202
With this PR, the shell now maintains the logical current working directory alongside with the physical one. To correctly create an absolute path and expand all
..
and.
from the logical path, the functions have been added to thebrush_core::sys::fs
crate:expand_tilde_with_home
- expands the tilde using the givenhome
directorymake_absolute
- makes the path absolute based on the givenbase
path.normalize_lexically
- performs canonicalization without touching the filesystem.Posix notes:
There is a special handling for paths with double slashes, such as
//users/home
See: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
Windows notes
There is a lot of special handling for Windows weird path formats:
\\server\share\my_dir
.\\?\C$\super_path
, this paths must not be normalized.\\.\Pipe
and UNC with the device namespace\\.\UNC\
.C:iamrelative
.See: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
See: The book of windows file path: https://chrisdenton.github.io/omnipath/
I've written a lot of tests, trying to cover all the special cases.