coreutils
coreutils copied to clipboard
cksum: implement -a
Closes #3812
I know it is a draft and we will squash them but could you please make the commit message a bit more explicit :)
I know it is a draft and we will squash them but could you please make the commit message a bit more explicit :)
I'm sorry. Let me squash them and present a little better commit first.
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU test failed: tests/misc/timeout. tests/misc/timeout is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
GNU test failed: tests/misc/cksum. tests/misc/cksum is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU test failed: tests/misc/cksum. tests/misc/cksum is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU test failed: tests/misc/cksum. tests/misc/cksum is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/misc/timeout. tests/misc/timeout is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU test failed: tests/misc/cksum. tests/misc/cksum is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU test failed: tests/misc/timeout. tests/misc/timeout is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
GNU test failed: tests/misc/timeout. tests/misc/timeout is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
GNU test failed: tests/misc/timeout. tests/misc/timeout is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
Hi @sylvestre I basically finish this PR. Are you willing to take a look to ensure things on the right direction?
GNU testsuite comparison:
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
GNU testsuite comparison:
Congrats! The gnu test tests/misc/timeout is no longer failing!
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
The object safety thing is annoying. I tried some things to get rid of it. What worked is to never box it, because we don't really have to. Instead we can do this:
fn cksum_algo<'a, I>(algorithm: &str, files: I) -> UResult<()>
where
I: Iterator<Item = &'a OsStr>,
{
match algorithm {
"sysv" => cksum::<_, SYSV>("SYSV", files),
"bsd" => cksum::<_, BSD>("BSD", files),
...
}
fn cksum<'a, I, D>(algo_name: &'static str, files: I) -> UResult<()>
where
I: Iterator<Item = &'a OsStr>,
D: Digest
{ ... }
pub trait Digest {
const OUTPUT_BITS: usize;
const OUTPUT_BYTES: usize = (Self::OUTPUT_BITS + 7) / 8;
fn new() -> Self;
fn hash_update(&mut self, input: &[u8]);
fn hash_finalize(&mut self, out: &mut [u8]);
fn result_str(&mut self) -> String {
let mut buf: Vec<u8> = vec![0; Self::OUTPUT_BYTES];
self.hash_finalize(&mut buf);
encode(buf)
}
}
But I can also do this after this PR is merged.
The object safety thing is annoying. I tried some things to get rid of it. What worked is to never box it, because we don't really have to. Instead we can do this:
fn cksum_algo<'a, I>(algorithm: &str, files: I) -> UResult<()> where I: Iterator<Item = &'a OsStr>, { match algorithm { "sysv" => cksum::<_, SYSV>("SYSV", files), "bsd" => cksum::<_, BSD>("BSD", files), ... } fn cksum<'a, I, D>(algo_name: &'static str, files: I) -> UResult<()> where I: Iterator<Item = &'a OsStr>, D: Digest { ... } pub trait Digest { const OUTPUT_BITS: usize; const OUTPUT_BYTES: usize = (Self::OUTPUT_BITS + 7) / 8; fn new() -> Self; fn hash_update(&mut self, input: &[u8]); fn hash_finalize(&mut self, out: &mut [u8]); fn result_str(&mut self) -> String { let mut buf: Vec<u8> = vec![0; Self::OUTPUT_BYTES]; self.hash_finalize(&mut buf); encode(buf) } }
But I can also do this after this PR is merged.
Cool I can give it a try in another PR.
I'll do that change to Digest
because by experimenting I already basically have a branch ready. I'll ping you for review though, I'll be interested to see your feedback on it.
Thank you!
GNU testsuite comparison:
Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
Alright, time to merge this! Thanks!
thank you too!