Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cksum: implement -z #6178

Open
sylvestre opened this issue Apr 1, 2024 · 6 comments · May be fixed by #6180
Open

cksum: implement -z #6178

sylvestre opened this issue Apr 1, 2024 · 6 comments · May be fixed by #6180
Labels

Comments

@sylvestre
Copy link
Sponsor Contributor

       -z, --zero
              end each output line with NUL, not newline, and disable file name escaping

we don't have it currently. Should be easy!

@orangeng orangeng linked a pull request Apr 2, 2024 that will close this issue
@orangeng
Copy link

orangeng commented Apr 2, 2024

Hi, I'm attempting to work on this issue and have linked a draft PR.

I have added the --zero option and implemented the nul/newline by changing the instances of println! to print!, then adding an "\0" or "\n" based on the existence of the flag. Is such an approach acceptable?

I'm currently trying to figure out the 2nd use of the flag, which is "and disable file name escaping". Any guidance on this would be much appreciated!

@cakebaker cakebaker linked a pull request Apr 2, 2024 that will close this issue
@dchenbecker
Copy link

@orangeng I did some digging and if you look at the output_file function in digest.c, you'll see where the -z flag is also used to control whether "problematic characters" in the filename are escaped:

https://github.com/coreutils/coreutils/blob/v9.5/src/digest.c#L1050

They basically check if the delimiter is "\n" and if it is, then they do some special handling of the filename. Looking through the comparable code in https://github.com/uutils/coreutils/blob/main/src/uu/cksum/src/cksum.rs, I don't see anywhere where any escaping is being done, so it may be that -z is already implicitly being handled and that we need to implement escaping for when -z isn't specified.

@orangeng
Copy link

orangeng commented Apr 15, 2024

Thanks @dchenbecker for the insights! I'm not sure about looking at the GNU coreutils source code. But at least according to the info cksum and just running the GNU coreutils version I have also noticed that -z is also used for special handling of the filenames. Specifically, the special handling happens when there is no -z flag and non-legacy algorithms (not BSD, SYSV, CRC).

Right now, the special handling of filenames isn't handled. So our behaviour is consistent with having -z (which is ignore special handling). I will add the code for special handling in cases without -z.

@dchenbecker
Copy link

Right, that's what I meant. I think we don't currently do any escaping which means that we're not consistent with filename handling when -z is not specified.

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Apr 16, 2024

@dchenbecker Please don't look at or link the GNU source code. That policy is our guarantee that uutils is original code. The documentation fair game though.

In any case, good find on that functionality!

@dchenbecker
Copy link

Apologies! I only looked at digest.c, so I'll steer clear of any future contributions related to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants