cp: integer conversion panic on ppc64le
I'm packaging Nushell 0.105 for Alpine right now, and ppc64le is one of the supported architectures. Nushell's cp, which uses uu_cp underneath, failed the tests because of a panic:
---- commands::ucp::copies_files_with_glob_metachars::case_1 stdout ----
=== stderr
Error: × Main thread panicked.
├─▶ at /home/buildozer/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/
│ uu_cp-0.1.0/src/platform/linux.rs:69:54
╰─▶ called `Result::unwrap()` on an `Err` value: TryFromIntError(())
help: set the `RUST_BACKTRACE=1` environment variable to display a
backtrace.
thread 'commands::ucp::copies_files_with_glob_metachars::case_1' panicked at crates/nu-command/tests/commands/ucp.rs:1014:9:
assertion failed: actual.err.is_empty()
Full log: https://gitlab.alpinelinux.org/kaathewise/aports/-/jobs/1891916
This is the code which fails:
https://github.com/uutils/coreutils/blob/18b963ed6f612ac30ebca92426280cf4c1451f6a/src/uu/cp/src/platform/linux.rs#L64-L72
@kaathewisegit , Is there a way to reproduce it on a x86 machine?
I don't think so, @VenetiaFurtado, all of the tests pass on x86. QEMU could work, though
On ppc64, FICLONE is pub const FICLONE: u32 = 2147783689; which can't be directly converted into i32 (which is what musl ioctl takes). Wrapping conversion is needed from the linux_raw_sys constant there (but done in a way that also compiles on other platorms)
I'm quite new to Rust and I'm looking around for now. I've opened a PR https://github.com/uutils/coreutils/pull/8637 with a fix that looks too simple to be the real fix. I expected that there would be some obstacles on the way. @dezgeg Can you or someone else criticize it if possible?
I'm quite new to Rust and I'm looking around for now. I've opened a PR #8637 with a fix that looks too simple to be the real fix. I expected that there would be some obstacles on the way. @dezgeg Can you or someone else criticize it if possible?
Good find, that does sound like it should work (assuming the linter likes it).
@dezgeg in fact there is libc::FICLONE, I can simply use it instead of linux_raw_sys
smth like
let result = unsafe { libc::ioctl(dst_fd, libc::FICLONE, src_fd) };
opened a Pull Request https://github.com/uutils/coreutils/pull/8641