Repository navigation
Conversation
|
sorry but it needs to be rebased |
Done. |
|
Ping. |
Add the `-s`/`--sysroot` option present in upstream util-linux but previously missing. All hardcoded `/sys/` and `/proc/` paths in `sysfs.rs` are threaded through a `root: &Path` parameter; the default root is `/` so behaviour without the flag is unchanged. To support this cleanly, introduce a new local shared crate `uulinux` with a `join_under_root(root, path) -> PathBuf` helper that prepends a sysroot to an absolute system path without discarding the root (unlike `Path::join`). Also use it in `lsmem` to replace the existing hand-rolled path construction there. Add unit tests for `join_under_root` and Linux integration tests for `lscpu --sysroot` using a minimal fake sysfs/procfs tree.
| json: matches.get_flag(options::JSON), | ||
| }; | ||
|
|
||
| let sysroot = matches |
There was a problem hiding this comment.
could be value_parser!(PathBuf) with default_value("/"), no?
| pub fn read_online_cpus(root: &Path) -> String { | ||
| let path = join_under_root(root, Path::new("/sys/devices/system/cpu/online")); | ||
| fs::read_to_string(path) | ||
| .expect("Could not read sysfs") |
There was a problem hiding this comment.
with a wrong --sysroot this now panics
please return a proper error instead (same for the unwrap in CpuTopology::new and read_cpu_caches)
and add a test with a missing dir
| /// | ||
| /// Unlike [`Path::join`], this never discards `root` when `path` is absolute. | ||
| /// Useful for prepending a sysroot to a system path like `/sys/devices/...`. | ||
| pub fn join_under_root(root: &Path, path: &Path) -> PathBuf { |
There was a problem hiding this comment.
do we really need a new crate for a 2 lines function? :)
also uulinux seems like a too generic name
| MAIN_SEPARATOR, | ||
| opts.sysmem.trim_start_matches(MAIN_SEPARATOR) | ||
| ); | ||
| opts.sysmem = join_under_root(Path::new(sysroot), Path::new(&opts.sysmem)) |
There was a problem hiding this comment.
unrelated to lscpu, please move it to a separate pr
also it changes the behavior with --sysroot "" (now a relative path)
| .succeeds() | ||
| .no_stderr() | ||
| .stdout_contains("CPU(s):") | ||
| .stdout_contains("2") |
There was a problem hiding this comment.
"2" will match almost anything
could you please check the full lines, e.g. "CPU(s): 2"?
|
|
||
| #[test] | ||
| #[cfg(target_os = "linux")] | ||
| fn test_sysroot_long_flag() { |
There was a problem hiding this comment.
do we need this test? clap already guarantees it
Add the
-s/--sysrootoption present in upstream util-linux but previously missing. All hardcoded/sys/and/proc/paths insysfs.rsare threaded through aroot: &Pathparameter; the default root is/so behaviour without the flag is unchanged.To support this cleanly, introduce a new local shared crate
uulinuxwith ajoin_under_root(root, path) -> PathBufhelper that prepends a sysroot to an absolute system path without discarding the root (unlikePath::join). Also use it inlsmemto replace the existing hand-rolled path construction there.Add unit tests for
join_under_rootand Linux integration tests forlscpu --sysrootusing a minimal fake sysfs/procfs tree.