From d38797bb5032ba96aad0fb2c1bf62a5f2ee2901e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 26 May 2023 18:53:30 +0200 Subject: [PATCH 01/13] mv: Show 'skipped' when a file isn't overwriten Should fix tests/mv/mv-n.sh --- src/uu/mv/src/mv.rs | 14 ++++++++++---- tests/by-util/test_mv.rs | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 831b362ae..5ca677c69 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -440,13 +440,19 @@ fn rename( match b.overwrite { OverwriteMode::NoClobber => { - return Err(io::Error::new( - io::ErrorKind::Other, - format!("not replacing {}", to.quote()), - )); + let err_msg = if b.verbose { + println!("skipped {}", to.quote()); + String::new() + } else { + format!("not replacing {}", to.quote()) + }; + return Err(io::Error::new(io::ErrorKind::Other, err_msg)); } OverwriteMode::Interactive => { if !prompt_yes!("overwrite {}?", to.quote()) { + if b.verbose { + println!("skipped {}", to.quote()); + } return Err(io::Error::new(io::ErrorKind::Other, "")); } } diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 39eaed1e7..f73d3249d 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1243,6 +1243,29 @@ fn test_mv_info_self() { .stderr_contains("mv: cannot move 'dir2' to a subdirectory of itself, 'dir2/dir2'"); } +#[test] +fn test_mv_arg_interactive_skipped() { + let (at, mut ucmd) = at_and_ucmd!(); + at.touch("a"); + at.touch("b"); + ucmd.args(&["-vi", "a", "b"]) + .pipe_in("N\n") + .ignore_stdin_write_error() + .fails() + .stderr_is("mv: overwrite 'b'? ") + .stdout_is("skipped 'b'\n"); +} + +#[test] +fn test_mv_arg_interactive_skipped_vin() { + let (at, mut ucmd) = at_and_ucmd!(); + at.touch("a"); + at.touch("b"); + ucmd.args(&["-vin", "a", "b"]) + .fails() + .stdout_is("skipped 'b'\n"); +} + #[test] fn test_mv_into_self_data() { let scene = TestScenario::new(util_name!()); From d98c81802fb419f1bef412f1c70dad207b6c4c94 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 May 2023 05:21:01 +0000 Subject: [PATCH 02/13] chore(deps): update rust crate clap to 4.3 --- Cargo.lock | 194 +++++++++++++++++++++++++++++++++++------------------ Cargo.toml | 2 +- 2 files changed, 131 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ffb998266..1d7f92724 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,42 +66,51 @@ dependencies = [ [[package]] name = "anstream" -version = "0.2.6" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" dependencies = [ "anstyle", "anstyle-parse", + "anstyle-query", "anstyle-wincon", - "concolor-override", - "concolor-query", + "colorchoice", "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "0.3.5" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" [[package]] name = "anstyle-parse" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" dependencies = [ "utf8parse", ] [[package]] -name = "anstyle-wincon" -version = "0.2.0" +name = "anstyle-query" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -280,18 +289,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6efb5f0a41b5ef5b50c5da28c07609c20091df0c1fc33d418fa2a7e693c2b624" +checksum = "93aae7a4192245f70fe75dd9157fc7b4a5bf53e88d30bd4396f7d8f9284d5acc" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671fcaa5debda4b9a84aa7fde49c907c8986c0e6ab927e04217c9cb74e7c8bc9" +checksum = "4f423e341edefb78c9caba2d9c7f7687d0e72e89df3ce3394554754393ac3990" dependencies = [ "anstream", "anstyle", @@ -313,9 +322,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" [[package]] name = "clap_mangen" @@ -337,27 +346,18 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "compare" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "120133d4db2ec47efe2e26502ee984747630c67f51974fca0b6c1340cf2368d3" -[[package]] -name = "concolor-override" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" - -[[package]] -name = "concolor-query" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" -dependencies = [ - "windows-sys", -] - [[package]] name = "console" version = "0.15.7" @@ -368,7 +368,7 @@ dependencies = [ "lazy_static", "libc", "unicode-width", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -712,7 +712,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbcf33c2a618cbe41ee43ae6e9f2e48368cd9f9db2896f10167d8d762679f639" dependencies = [ "nix", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -862,7 +862,7 @@ checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -911,7 +911,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall 0.2.16", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1231,7 +1231,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1243,7 +1243,7 @@ dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", "rustix 0.37.7", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1439,7 +1439,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1479,7 +1479,7 @@ dependencies = [ "libc", "mio", "walkdir", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1488,7 +1488,7 @@ version = "0.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df031e117bca634c262e9bd3173776844b6c17a90b3741c9163663b4385af76" dependencies = [ - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -1645,7 +1645,7 @@ dependencies = [ "libc", "redox_syscall 0.2.16", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2001,7 +2001,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys 0.1.4", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2015,7 +2015,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys 0.3.0", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2230,7 +2230,7 @@ dependencies = [ "fastrand", "redox_syscall 0.3.5", "rustix 0.37.7", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2258,7 +2258,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c9afddd2cec1c0909f06b00ef33f94ab2cc0578c4a610aa208ddfec8aa2b43a" dependencies = [ "rustix 0.36.14", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2546,7 +2546,7 @@ dependencies = [ "libc", "time", "uucore", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2603,7 +2603,7 @@ dependencies = [ "clap", "glob", "uucore", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -2726,7 +2726,7 @@ dependencies = [ "clap", "hostname", "uucore", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3028,7 +3028,7 @@ dependencies = [ "libc", "uucore", "walkdir", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3173,7 +3173,7 @@ dependencies = [ "libc", "nix", "uucore", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3201,7 +3201,7 @@ dependencies = [ "same-file", "uucore", "winapi-util", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3242,7 +3242,7 @@ dependencies = [ "humantime_to_duration", "time", "uucore", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3376,7 +3376,7 @@ dependencies = [ "clap", "libc", "uucore", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3421,7 +3421,7 @@ dependencies = [ "walkdir", "wild", "winapi-util", - "windows-sys", + "windows-sys 0.45.0", "z85", ] @@ -3574,7 +3574,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", ] [[package]] @@ -3583,13 +3592,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -3598,42 +3622,84 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "xattr" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 1621eca86..595be01f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -269,7 +269,7 @@ bstr = "1.5" bytecount = "0.6.3" byteorder = "1.4.3" chrono = { version="^0.4.25", default-features=false, features=["std", "alloc", "clock"]} -clap = { version = "4.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.3", features = ["wrap_help", "cargo"] } clap_complete = "4.3" clap_mangen = "0.2" compare = "0.1.0" From f02b2345ee289b8aafcbd2d5759a690e44fcb96e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 May 2023 06:36:45 +0000 Subject: [PATCH 03/13] chore(deps): update rust crate is-terminal to 0.4.7 --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d7f92724..d29da5145 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1236,14 +1236,14 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", "rustix 0.37.7", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 595be01f4..29e4244b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -288,7 +288,7 @@ glob = "0.3.1" half = "2.2" humantime_to_duration = "0.2.1" indicatif = "0.17" -is-terminal = "0.4.6" +is-terminal = "0.4.7" itertools = "0.10.5" libc = "0.2.144" lscolors = { version = "0.14.0", default-features=false, features = ["nu-ansi-term"] } From 2e070224a53a7066920827a5dc0b0a4a811805f6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 May 2023 06:36:49 +0000 Subject: [PATCH 04/13] chore(deps): update rust crate terminal_size to 0.2.6 --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d7f92724..49744bcf0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2253,12 +2253,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c9afddd2cec1c0909f06b00ef33f94ab2cc0578c4a610aa208ddfec8aa2b43a" +checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237" dependencies = [ - "rustix 0.36.14", - "windows-sys 0.45.0", + "rustix 0.37.7", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 595be01f4..0dccdbc75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -319,7 +319,7 @@ signal-hook = "0.3.15" smallvec = { version = "1.10", features = ["union"] } tempfile = "3.5.0" term_grid = "0.1.5" -terminal_size = "0.2.5" +terminal_size = "0.2.6" textwrap = { version="0.16.0", features=["terminal_size"] } thiserror = "1.0" time = { version="0.3" } From 8f9a328c6a4564a29408ec09bc2ada6647b384e8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 May 2023 06:36:57 +0000 Subject: [PATCH 05/13] fix(deps): update rust crate windows-sys to 0.48.0 --- Cargo.lock | 18 +++++++++--------- Cargo.toml | 2 +- src/uucore/Cargo.toml | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d7f92724..ba1a705fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2546,7 +2546,7 @@ dependencies = [ "libc", "time", "uucore", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -2603,7 +2603,7 @@ dependencies = [ "clap", "glob", "uucore", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -2726,7 +2726,7 @@ dependencies = [ "clap", "hostname", "uucore", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3028,7 +3028,7 @@ dependencies = [ "libc", "uucore", "walkdir", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3173,7 +3173,7 @@ dependencies = [ "libc", "nix", "uucore", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3201,7 +3201,7 @@ dependencies = [ "same-file", "uucore", "winapi-util", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3242,7 +3242,7 @@ dependencies = [ "humantime_to_duration", "time", "uucore", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3376,7 +3376,7 @@ dependencies = [ "clap", "libc", "uucore", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3421,7 +3421,7 @@ dependencies = [ "walkdir", "wild", "winapi-util", - "windows-sys 0.45.0", + "windows-sys 0.48.0", "z85", ] diff --git a/Cargo.toml b/Cargo.toml index 595be01f4..ab191d47a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -328,7 +328,7 @@ unicode-width = "0.1.10" utf-8 = "0.7.6" walkdir = "2.3" winapi-util = "0.1.5" -windows-sys = { version="0.45.0", default-features=false } +windows-sys = { version="0.48.0", default-features=false } xattr = "1.0.0" zip = { version = "0.6.6", default_features=false, features=["deflate"] } diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index ea7fb44f3..491e98868 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -58,7 +58,7 @@ tempfile = { workspace=true } [target.'cfg(target_os = "windows")'.dependencies] winapi-util = { version= "0.1.5", optional=true } -windows-sys = { version = "0.45.0", optional = true, default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation", "Win32_System_WindowsProgramming"] } +windows-sys = { version = "0.48.0", optional = true, default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation", "Win32_System_WindowsProgramming"] } [features] default = [] From 2ec70dc05dddc31ecf94abe57bb68ba7c808ef9b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 May 2023 06:37:02 +0000 Subject: [PATCH 06/13] fix(deps): update rust crate dns-lookup to v2 --- Cargo.lock | 12 ++++++------ src/uucore/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d7f92724..9e79da98a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -816,14 +816,14 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" [[package]] name = "dns-lookup" -version = "1.0.8" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53ecafc952c4528d9b51a458d1a8904b81783feff9fde08ab6ed2545ff396872" +checksum = "8f332aa79f9e9de741ac013237294ef42ce2e9c6394dc7d766725812f1238812" dependencies = [ "cfg-if", "libc", "socket2", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -2183,12 +2183,12 @@ checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" [[package]] name = "socket2" -version = "0.4.7" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" dependencies = [ "libc", - "winapi", + "windows-sys 0.48.0", ] [[package]] diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index ea7fb44f3..2c02ad3d3 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -20,7 +20,7 @@ path="src/lib/lib.rs" [dependencies] clap = { workspace=true } uucore_procs = { workspace=true } -dns-lookup = { version="1.0.8", optional=true } +dns-lookup = { version="2.0.2", optional=true } dunce = "1.0.4" wild = "2.1" glob = "0.3.1" From 6278c6f2d6bcd923c2ce294b13b822853a529030 Mon Sep 17 00:00:00 2001 From: John Shin Date: Mon, 29 May 2023 19:13:33 -0700 Subject: [PATCH 07/13] core: add octal and hex size parse support --- src/uucore/src/lib/parser/parse_size.rs | 126 ++++++++++++++++++++---- 1 file changed, 106 insertions(+), 20 deletions(-) diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index 60209d849..70b94fbcc 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -25,6 +25,12 @@ pub struct Parser<'parser> { pub default_unit: Option<&'parser str>, } +enum NumberSystem { + Decimal, + Octal, + Hexadecimal, +} + impl<'parser> Parser<'parser> { pub fn with_allow_list(&mut self, allow_list: &'parser [&str]) -> &mut Self { self.allow_list = Some(allow_list); @@ -62,32 +68,42 @@ impl<'parser> Parser<'parser> { /// assert_eq!(Ok(123), parse_size("123")); /// assert_eq!(Ok(9 * 1000), parse_size("9kB")); // kB is 1000 /// assert_eq!(Ok(2 * 1024), parse_size("2K")); // K is 1024 + /// assert_eq!(Ok(44251 * 1024), parse_size("0xACDBK")); /// ``` pub fn parse(&self, size: &str) -> Result { if size.is_empty() { return Err(ParseSizeError::parse_failure(size)); } - // Get the numeric part of the size argument. For example, if the - // argument is "123K", then the numeric part is "123". - let numeric_string: String = size.chars().take_while(|c| c.is_ascii_digit()).collect(); - let number: u64 = if numeric_string.is_empty() { - 1 - } else { - match numeric_string.parse() { - Ok(n) => n, - Err(_) => return Err(ParseSizeError::parse_failure(size)), + + let number_system: NumberSystem = self.determine_number_system(size); + + // Split the size argument into numeric and unit parts + // For example, if the argument is "123K", the numeric part is "123", and + // the unit is "K" + let (numeric_string, unit) = match number_system { + NumberSystem::Hexadecimal => { + let numeric_string: String = size + .chars() + .take(2) + .chain(size.chars().skip(2).take_while(|c| c.is_ascii_hexdigit())) + .collect(); + let unit: String = size.chars().skip(numeric_string.len()).collect(); + + (numeric_string, unit) + } + _ => { + let mut unit: String = size + .chars() + .rev() + .take_while(|c| c.is_alphabetic()) + .collect(); + unit = unit.chars().rev().collect(); + let numeric_string = size.chars().take(size.len() - unit.len()).collect(); + + (numeric_string, unit) } }; - - // Get the alphabetic units part of the size argument and compute - // the factor it represents. For example, if the argument is "123K", - // then the unit part is "K" and the factor is 1024. This may be the - // empty string, in which case, the factor is 1. - // - // The lowercase "b" (used by `od`, `head`, `tail`, etc.) means - // "block" and the Posix block size is 512. The uppercase "B" - // means "byte". - let mut unit: &str = &size[numeric_string.len()..]; + let mut unit: &str = unit.as_str(); if let Some(default_unit) = self.default_unit { // Check if `unit` is empty then assigns `default_unit` to `unit` @@ -115,6 +131,12 @@ impl<'parser> Parser<'parser> { } } + // Compute the factor the unit represents. + // empty string means the factor is 1. + // + // The lowercase "b" (used by `od`, `head`, `tail`, etc.) means + // "block" and the Posix block size is 512. The uppercase "B" + // means "byte". let (base, exponent): (u128, u32) = match unit { "" => (1, 0), "B" if self.capital_b_bytes => (1, 0), @@ -142,10 +164,60 @@ impl<'parser> Parser<'parser> { Ok(n) => n, Err(_) => return Err(ParseSizeError::size_too_big(size)), }; + + // parse string into u64 + let number: u64 = match number_system { + NumberSystem::Decimal => { + if numeric_string.is_empty() { + 1 + } else { + match numeric_string.parse() { + Ok(n) => n, + Err(_) => return Err(ParseSizeError::parse_failure(size)), + } + } + } + NumberSystem::Octal => { + let trimmed_string = numeric_string.trim_start_matches("0"); + match u64::from_str_radix(trimmed_string, 8) { + Ok(res) => res, + Err(_) => return Err(ParseSizeError::parse_failure(size)), + } + } + NumberSystem::Hexadecimal => { + let trimmed_string = numeric_string.trim_start_matches("0x"); + match u64::from_str_radix(trimmed_string, 16) { + Ok(res) => res, + Err(_) => return Err(ParseSizeError::parse_failure(size)), + } + } + }; + number .checked_mul(factor) .ok_or_else(|| ParseSizeError::size_too_big(size)) } + + fn determine_number_system(&self, size: &str) -> NumberSystem { + if size.len() <= 1 { + return NumberSystem::Decimal; + } + + if size.starts_with("0x") { + return NumberSystem::Hexadecimal; + } + + let num_digits: usize = size + .chars() + .take_while(|c| c.is_ascii_digit()) + .collect::() + .len(); + if size.starts_with("0") && num_digits > 1 { + return NumberSystem::Octal; + } + + NumberSystem::Decimal + } } /// Parse a size string into a number of bytes. @@ -336,7 +408,7 @@ mod tests { #[test] fn invalid_suffix() { - let test_strings = ["328hdsf3290", "5mib", "1e2", "1H", "1.2"]; + let test_strings = ["5mib", "1eb", "1H"]; for &test_string in &test_strings { assert_eq!( parse_size(test_string).unwrap_err(), @@ -450,4 +522,18 @@ mod tests { assert!(parser.parse("1B").is_err()); assert!(parser.parse("B").is_err()); } + + #[test] + fn parse_octal_size() { + assert_eq!(Ok(63), parse_size("077")); + assert_eq!(Ok(528), parse_size("01020")); + assert_eq!(Ok(668 * 1024), parse_size("01234K")); + } + + #[test] + fn parse_hex_size() { + assert_eq!(Ok(10), parse_size("0xA")); + assert_eq!(Ok(94722), parse_size("0x17202")); + assert_eq!(Ok(44251 * 1024), parse_size("0xACDBK")); + } } From 3ca003846dc2d272d56a27043cf73c9b5dc6b427 Mon Sep 17 00:00:00 2001 From: John Shin Date: Mon, 29 May 2023 20:10:16 -0700 Subject: [PATCH 08/13] shred: add support for hex and octal size --- src/uu/shred/src/shred.rs | 42 ++++++++++--------------------------- tests/by-util/test_shred.rs | 11 ++++++++++ 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 89f857b19..1ceffe995 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -19,6 +19,7 @@ use std::os::unix::prelude::PermissionsExt; use std::path::{Path, PathBuf}; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; +use uucore::parse_size::parse_size; use uucore::{format_usage, help_about, help_section, help_usage, show, show_error, show_if_err}; const ABOUT: &str = help_about!("shred.md"); @@ -318,38 +319,17 @@ pub fn uu_app() -> Command { ) } -// TODO: Add support for all postfixes here up to and including EiB -// http://www.gnu.org/software/coreutils/manual/coreutils.html#Block-size fn get_size(size_str_opt: Option) -> Option { - size_str_opt.as_ref()?; - - let mut size_str = size_str_opt.as_ref().unwrap().clone(); - // Immutably look at last character of size string - let unit = match size_str.chars().last().unwrap() { - 'K' => { - size_str.pop(); - 1024u64 - } - 'M' => { - size_str.pop(); - (1024 * 1024) as u64 - } - 'G' => { - size_str.pop(); - (1024 * 1024 * 1024) as u64 - } - _ => 1u64, - }; - - let coefficient = match size_str.parse::() { - Ok(u) => u, - Err(_) => { - show_error!("{}: Invalid file size", size_str_opt.unwrap().maybe_quote()); - std::process::exit(1); - } - }; - - Some(coefficient * unit) + match size_str_opt { + Some(size) => match parse_size(size.as_str()) { + Ok(res) => Some(res), + Err(_) => { + show_error!("invalid file size: {}", size.quote()); + std::process::exit(1) + } + }, + None => None, + } } fn pass_name(pass_type: &PassType) -> String { diff --git a/tests/by-util/test_shred.rs b/tests/by-util/test_shred.rs index 58db09cbd..a34345aee 100644 --- a/tests/by-util/test_shred.rs +++ b/tests/by-util/test_shred.rs @@ -51,3 +51,14 @@ fn test_shred_force() { // file_a was deleted. assert!(!at.file_exists(file)); } + +#[test] +fn test_hex() { + let (at, mut ucmd) = at_and_ucmd!(); + + let file = "test_hex"; + + at.touch(file); + + ucmd.arg("--size=0x10").arg(file).succeeds(); +} From 6cadffc8f1879ba1174d30d10cadc9ac273498a3 Mon Sep 17 00:00:00 2001 From: John Shin Date: Mon, 29 May 2023 20:59:21 -0700 Subject: [PATCH 09/13] core: fix clippy warning for size parser --- src/uucore/src/lib/parser/parse_size.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index 70b94fbcc..be642ef8b 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -178,7 +178,7 @@ impl<'parser> Parser<'parser> { } } NumberSystem::Octal => { - let trimmed_string = numeric_string.trim_start_matches("0"); + let trimmed_string = numeric_string.trim_start_matches('0'); match u64::from_str_radix(trimmed_string, 8) { Ok(res) => res, Err(_) => return Err(ParseSizeError::parse_failure(size)), @@ -212,7 +212,7 @@ impl<'parser> Parser<'parser> { .take_while(|c| c.is_ascii_digit()) .collect::() .len(); - if size.starts_with("0") && num_digits > 1 { + if size.starts_with('0') && num_digits > 1 { return NumberSystem::Octal; } From 8ef926c6e863c0b274df9c33b326d45e7e24b10e Mon Sep 17 00:00:00 2001 From: John Shin Date: Tue, 30 May 2023 00:26:17 -0700 Subject: [PATCH 10/13] core: refactor num and unit split --- src/uucore/src/lib/parser/parse_size.rs | 31 +++++++------------------ 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index be642ef8b..716cf8d79 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -80,30 +80,15 @@ impl<'parser> Parser<'parser> { // Split the size argument into numeric and unit parts // For example, if the argument is "123K", the numeric part is "123", and // the unit is "K" - let (numeric_string, unit) = match number_system { - NumberSystem::Hexadecimal => { - let numeric_string: String = size - .chars() - .take(2) - .chain(size.chars().skip(2).take_while(|c| c.is_ascii_hexdigit())) - .collect(); - let unit: String = size.chars().skip(numeric_string.len()).collect(); - - (numeric_string, unit) - } - _ => { - let mut unit: String = size - .chars() - .rev() - .take_while(|c| c.is_alphabetic()) - .collect(); - unit = unit.chars().rev().collect(); - let numeric_string = size.chars().take(size.len() - unit.len()).collect(); - - (numeric_string, unit) - } + let numeric_string: String = match number_system { + NumberSystem::Hexadecimal => size + .chars() + .take(2) + .chain(size.chars().skip(2).take_while(|c| c.is_ascii_hexdigit())) + .collect(), + _ => size.chars().take_while(|c| c.is_ascii_digit()).collect(), }; - let mut unit: &str = unit.as_str(); + let mut unit: &str = &size[numeric_string.len()..]; if let Some(default_unit) = self.default_unit { // Check if `unit` is empty then assigns `default_unit` to `unit` From 0465553f6ebd36cebf4d0d71a476b957cb2b29fc Mon Sep 17 00:00:00 2001 From: John Shin Date: Tue, 30 May 2023 00:27:09 -0700 Subject: [PATCH 11/13] core: size parser treat 000 as decimal --- src/uucore/src/lib/parser/parse_size.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index 716cf8d79..af4cf990d 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -197,7 +197,8 @@ impl<'parser> Parser<'parser> { .take_while(|c| c.is_ascii_digit()) .collect::() .len(); - if size.starts_with('0') && num_digits > 1 { + let all_zeros = size.chars().all(|c| c == '0'); + if size.starts_with('0') && num_digits > 1 && !all_zeros { return NumberSystem::Octal; } From a3979201836e97cea203eee0f328d89ff75d8a7b Mon Sep 17 00:00:00 2001 From: John Shin Date: Tue, 30 May 2023 00:33:14 -0700 Subject: [PATCH 12/13] core: refactor parse_number in size parser --- src/uucore/src/lib/parser/parse_size.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index af4cf990d..c6a02dfae 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -156,25 +156,16 @@ impl<'parser> Parser<'parser> { if numeric_string.is_empty() { 1 } else { - match numeric_string.parse() { - Ok(n) => n, - Err(_) => return Err(ParseSizeError::parse_failure(size)), - } + self.parse_number(&numeric_string, 10, size)? } } NumberSystem::Octal => { let trimmed_string = numeric_string.trim_start_matches('0'); - match u64::from_str_radix(trimmed_string, 8) { - Ok(res) => res, - Err(_) => return Err(ParseSizeError::parse_failure(size)), - } + self.parse_number(trimmed_string, 8, size)? } NumberSystem::Hexadecimal => { let trimmed_string = numeric_string.trim_start_matches("0x"); - match u64::from_str_radix(trimmed_string, 16) { - Ok(res) => res, - Err(_) => return Err(ParseSizeError::parse_failure(size)), - } + self.parse_number(trimmed_string, 16, size)? } }; @@ -204,6 +195,16 @@ impl<'parser> Parser<'parser> { NumberSystem::Decimal } + + fn parse_number( + &self, + numeric_string: &str, + radix: u32, + original_size: &str, + ) -> Result { + u64::from_str_radix(numeric_string, radix) + .map_err(|_| ParseSizeError::ParseFailure(original_size.to_string())) + } } /// Parse a size string into a number of bytes. From 58bf9989199c0713ed6d4e385a594f0424e100cc Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 30 May 2023 15:49:53 +0200 Subject: [PATCH 13/13] Ignore some words --- src/uucore/src/lib/parser/parse_size.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index c6a02dfae..2ea84e389 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -3,7 +3,7 @@ // * For the full copyright and license information, please view the LICENSE // * file that was distributed with this source code. -// spell-checker:ignore (ToDO) hdsf ghead gtail +// spell-checker:ignore (ToDO) hdsf ghead gtail ACDBK hexdigit use std::error::Error; use std::fmt;