coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

feat: `coreutils shred --random-source`

Open mobley-trent opened this issue 1 year ago • 19 comments

Closes #5711

mobley-trent avatar Dec 29 '23 09:12 mobley-trent

i know it is a draft but could you please add tests ? :) thanks

sylvestre avatar Dec 29 '23 09:12 sylvestre

Hello @sylvestre I was getting to that 😄

mobley-trent avatar Dec 29 '23 10:12 mobley-trent

Hey @cakebaker I have implemented the basic functionality to read some random bytes from the file. Are we supposed to print them on the terminal ? The command doesn't seem to do this at the moment

mobley-trent avatar Dec 29 '23 10:12 mobley-trent

it should behave like GNU $ /usr/bin/shred --random-source=myfile a doesn't return anything

sylvestre avatar Dec 29 '23 10:12 sylvestre

GNU testsuite comparison:

GNU test failed: tests/shred/shred-exact. tests/shred/shred-exact is passing on 'main'. Maybe you have to rebase?

github-actions[bot] avatar Dec 29 '23 11:12 github-actions[bot]

to reproduce the issue: bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/shred/shred-exact

sylvestre avatar Dec 29 '23 11:12 sylvestre

Screenshot 2024-01-03 104733

Currently, I'm getting this error when trying to run the command. Any tips on how to debug @sylvestre ?

mobley-trent avatar Jan 03 '24 07:01 mobley-trent

Screenshot 2024-01-03 105853

The hello.txt file is a dummy file I placed in the root of the repo

mobley-trent avatar Jan 03 '24 08:01 mobley-trent

could you please replace your screenshot by copy and paste of the text? screenshots are terrible for accessibility and search thanks

sylvestre avatar Jan 03 '24 08:01 sylvestre

/usr/bin/shred --random-source hello.txt a

/usr/bin/shred --random-source hello.txt

mobley-trent avatar Jan 03 '24 09:01 mobley-trent

this is probably an argument issue with clap

sylvestre avatar Jan 06 '24 21:01 sylvestre

I hope I'm understanding this correctly, but --random-source should have .require_equals(true) for this to work properly. (Another thing that will be solved by my new argument parser! 😄)

tertsdiepraam avatar Jan 08 '24 09:01 tertsdiepraam

GNU testsuite comparison:

GNU test failed: tests/shred/shred-exact. tests/shred/shred-exact is passing on 'main'. Maybe you have to rebase?

github-actions[bot] avatar Jan 09 '24 08:01 github-actions[bot]

The command seems to work after pulling from the upstream:main branch. @sylvestre @tertsdiepraam I don't think requires_equals is necessary as the file path is the only necessary input of the function. If not, please explain how it would be necessary in this case 🙂

mobley-trent avatar Jan 09 '24 10:01 mobley-trent

Sorry, I've misunderstood your previous explanation :)

tertsdiepraam avatar Jan 09 '24 11:01 tertsdiepraam

I guess you saw that the test is failing, right?

sylvestre avatar Jan 09 '24 12:01 sylvestre

The test I implemented in test_shred.rs is passing. I don't know how to debug the GNU failing tests in the CI @sylvestre I think the extra argument in this case would be the random seed @tertsdiepraam

mobley-trent avatar Jan 09 '24 12:01 mobley-trent

Before the GNU tests, the rust test suite is broken: https://github.com/uutils/coreutils/actions/runs/7458371831/job/20292245014?pr=5746

Example:

--- TRY 3 STDERR:        coreutils::tests test_shred::test_shred_remove_wipe ---
thread 'test_shred::test_shred_remove_wipe' panicked at 'Command was expected to succeed.
stdout = 
 stderr = thread 'main' panicked at 'cannot sample empty range', /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rng.rs:134:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
', tests/by-util/test_shred.rs:70:41
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
   2: tests::common::util::CmdResult::success
             at ./tests/common/util.rs:388:9
   3: tests::common::util::UCommand::succeeds
             at ./tests/common/util.rs:1568:9
   4: tests::test_shred::test_shred_remove_wipe
             at ./tests/by-util/test_shred.rs:70:5
   5: tests::test_shred::test_shred_remove_wipe::{{closure}}
             at ./tests/by-util/test_shred.rs:64:29
   6: core::ops::function::FnOnce::call_once
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

cargo test --features unix test_shred should fail on your system

sylvestre avatar Jan 09 '24 12:01 sylvestre

I think the problems are also rooted in the fact that I'm on Windows 😅

mobley-trent avatar Jan 09 '24 14:01 mobley-trent