coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

cksum: implement -a

Open howjmay opened this issue 1 year ago • 19 comments

Closes #3812

howjmay avatar Feb 13 '23 13:02 howjmay

I know it is a draft and we will squash them but could you please make the commit message a bit more explicit :)

sylvestre avatar Feb 13 '23 14:02 sylvestre

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.

howjmay avatar Feb 13 '23 15:02 howjmay

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?

github-actions[bot] avatar Feb 13 '23 18:02 github-actions[bot]

GNU testsuite comparison:

GNU test failed: tests/misc/cksum. tests/misc/cksum is passing on 'main'. Maybe you have to rebase?

github-actions[bot] avatar Feb 14 '23 04:02 github-actions[bot]

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?

github-actions[bot] avatar Feb 14 '23 04:02 github-actions[bot]

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?

github-actions[bot] avatar Feb 14 '23 04:02 github-actions[bot]

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?

github-actions[bot] avatar Feb 14 '23 06:02 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

github-actions[bot] avatar Feb 14 '23 07:02 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

github-actions[bot] avatar Feb 14 '23 07:02 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

github-actions[bot] avatar Feb 14 '23 09:02 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

github-actions[bot] avatar Feb 14 '23 09:02 github-actions[bot]

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?

github-actions[bot] avatar Feb 14 '23 10:02 github-actions[bot]

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?

github-actions[bot] avatar Feb 14 '23 13:02 github-actions[bot]

GNU testsuite comparison:

GNU test failed: tests/misc/timeout. tests/misc/timeout is passing on 'main'. Maybe you have to rebase?

github-actions[bot] avatar Feb 14 '23 13:02 github-actions[bot]

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?

github-actions[bot] avatar Feb 14 '23 13:02 github-actions[bot]

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?

github-actions[bot] avatar Feb 14 '23 18:02 github-actions[bot]

Hi @sylvestre I basically finish this PR. Are you willing to take a look to ensure things on the right direction?

howjmay avatar Feb 15 '23 07:02 howjmay

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?

github-actions[bot] avatar Feb 15 '23 09:02 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/misc/timeout is no longer failing!

github-actions[bot] avatar Feb 18 '23 14:02 github-actions[bot]

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

github-actions[bot] avatar Feb 19 '23 11:02 github-actions[bot]

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.

tertsdiepraam avatar Feb 21 '23 17:02 tertsdiepraam

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.

howjmay avatar Feb 22 '23 03:02 howjmay

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.

tertsdiepraam avatar Feb 22 '23 08:02 tertsdiepraam

Thank you!

howjmay avatar Feb 22 '23 13:02 howjmay

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!

github-actions[bot] avatar Feb 23 '23 05:02 github-actions[bot]

Alright, time to merge this! Thanks!

tertsdiepraam avatar Feb 23 '23 11:02 tertsdiepraam

thank you too!

howjmay avatar Feb 23 '23 16:02 howjmay