Repository navigation
Conversation
| }; | ||
| // Follow each link separately: canonicalize would discard the utility name | ||
| // in an intermediate link such as dummy -> true -> coreutils. | ||
| for _ in 0..40 { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
f918ead to
7477559
Compare
| fn utility_from_symlink<T>(utils: &UtilityMap<T>, binary: &Path) -> Option<&'static str> { | ||
| use std::os::unix::fs::PermissionsExt; | ||
|
|
||
| // binary_path can return argv[0] on any Unix target; AT_EXECFN is not |
There was a problem hiding this comment.
Would you restrict this to Linux and remove PATH lookup?
37d5117 to
ad408e9
Compare
| let execfn_bytes = execfn.to_bytes(); | ||
| let exec_path = Path::new(OsStr::from_bytes(execfn_bytes)); | ||
| let argv0 = args.next().unwrap(); | ||
| let same_name = execfn_bytes.rsplit(|&b| b == b'/').next() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ad408e9 to
6dfc6f7
Compare
| target_env = "gnu", | ||
| feature = "true", | ||
| feature = "false", | ||
| feature = "echo" |
0355994 to
72acd75
Compare
|
please also update the PR description: it says "On Unix" and "symlink chain", but the code does one readlink and only on linux glibc. thanks |
| return None; | ||
| } | ||
| utils | ||
| .keys() |
There was a problem hiding this comment.
this is almost the same matching code as matched_util in main(), could be dedup, no?
| // the kernel reports /dev/fd/* and memfd_create/glibc's fallback /proc/self/fd/* | ||
| // argv0 is not full-path when called from PATH | ||
| // Otherwise keep the kernel path: argv0 may lack the directory after PATH lookup. | ||
| if execfn_bytes.rsplit(|&b| b == b'/').next() == argv0.as_bytes().rsplit(|&b| b == b'/').next() |
There was a problem hiding this comment.
this isn't just a refactor: when the names match we now return execfn instead of argv0 and skip the shebang/proc checks, is that intended?
There was a problem hiding this comment.
Yes. Because we need full path.
| let at = &scene.fixtures; | ||
| at.mkdir("bin"); | ||
| symlink_file(&scene.bin_path, at.plus("bin/echo")).unwrap(); | ||
| for (index, target) in [std::path::PathBuf::from("bin/echo"), at.plus("bin/echo")] |
There was a problem hiding this comment.
two nested loops make this test hard to read, could you please write the cases out plainly?
|
|
||
| #[test] | ||
| #[cfg(all(target_os = "linux", target_env = "gnu", feature = "echo"))] | ||
| fn utility_alias_symlink_chain() { |
There was a problem hiding this comment.
please add a test that dummy -> coreutils and dummy -> foo -> coreutils still fail with the not found error
72acd75 to
728cba7
Compare
| #[test] | ||
| #[cfg(all(target_os = "linux", target_env = "gnu", feature = "echo"))] | ||
| fn utility_alias_without_path() { | ||
| use std::os::unix::process::CommandExt; |
There was a problem hiding this comment.
this is almost the same as the relative_target_absolute_alias case, could be another case of the rstest above, no?
On Linux with glibc, resolve an unrecognized invocation name from its immediate symlink target. Reuse binary_path's kernel invocation path, retaining its full directory after PATH lookup. Cover relative and absolute targets, shell PATH invocation, argument forwarding, and invocation with PATH unset using echo. Closes uutils#10946.
728cba7 to
c4dc57b
Compare
On Linux with glibc, resolve an unrecognized invocation name through one symlink lookup, including aliases found through PATH. This lets dummy -> true -> coreutils run true.
Add coverage for relative links, PATH lookup, argument forwarding, utility exit status, and unknown aliases.
Closes #10946.