-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add Physical mode to realpath #2459
Add Physical mode to realpath #2459
Conversation
96771ef
to
94fc6f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Great to see this functionality become available for other utils as well. I just have some small suggestions and please update the doc comment on the canonizalize
function to include the ResolveMode
argument.
src/uucore/src/lib/features/fs.rs
Outdated
match fs::canonicalize(result) { | ||
Err(e) => return Err(e), | ||
Ok(path) => { | ||
result = path; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match fs::canonicalize(result) { | |
Err(e) => return Err(e), | |
Ok(path) => { | |
result = path; | |
} | |
result = canonicalize(result)?; |
src/uu/realpath/src/realpath.rs
Outdated
.arg( | ||
Arg::with_name(OPT_LOGICAL) | ||
.short("L") | ||
.long(OPT_LOGICAL) | ||
.help("resolve '..' components before symlinks"), | ||
) | ||
.arg( | ||
Arg::with_name(OPT_PHYSICAL) | ||
.short("P") | ||
.long(OPT_PHYSICAL) | ||
.help("resolve symlinks as encountered (default)"), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these options should override each other. See overrides_with
src/uucore/src/lib/features/fs.rs
Outdated
pub enum ResolveMode { | ||
/// Resolve symlinks as encountered when processing the path | ||
Physical, | ||
|
||
/// Resolve '..' elements before symlinks | ||
Logical, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be totally wrong here and it's a remnant of the existing implementation, but I feel like the concerns are not well separated between ResolveMode
and CanonicalizeMode
. I would expect something like:
enum ResolveMode {
None,
Logical,
Physical,
}
enum MissingHandling {
Normal,
Existing,
Missing,
}
But maybe that doesn't make sense for a reason I'm not seeing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think your suggestion is correct. The CanonicalizeMode
is a remnant of the existing implementation and the options for handling symlinks should be grouped together.
48bbb15
to
fcc7572
Compare
I'm not sure why the windows tests are failing, as I don't have a windows box set up to test on. Any suggestions for potential fixes would be appreciated. |
I've previously tested some utils on wine, maybe that would work? I could also take a look at it later |
Ok, I have discovered the cause for the test failures. When using the
The |
fcc7572
to
9d287f6
Compare
Ok, I have a windows vm that I can test with and I made a change to remove the extended path length prefix. Now there's another failure, which also happens on my vm when I run |
cf371c2
to
efe2c6e
Compare
Did you look how it performs again the gnu testsuite ? |
I had a look and the behaviour of |
This adds the 'Physical Mode' and 'Logical Mode' switches to realpath, which control when symlinks are resolved.
efe2c6e
to
0e04f95
Compare
The problem with |
Thanks! The test failures are all because of a bug in a |
Partly fixes issue #2253. |
This adds the 'Physical Mode' and 'Logical Mode' switches to realpath, which control when symlinks are resolved.
For other utilities that use the
canonicalize
function I have preserved the current behaviour.