Page MenuHomeFreeBSD

preserve: run a command and replace its output only if it has changed
Needs ReviewPublic

Authored by des on Mar 29 2023, 5:58 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 27 2023, 2:24 AM
Unknown Object (File)
Dec 20 2023, 5:42 AM
Unknown Object (File)
Dec 13 2023, 6:53 AM
Unknown Object (File)
Nov 16 2023, 9:10 AM
Unknown Object (File)
Nov 12 2023, 10:36 AM
Unknown Object (File)
Oct 15 2023, 8:15 AM
Unknown Object (File)
Oct 14 2023, 5:41 PM
Unknown Object (File)
Oct 14 2023, 5:41 PM
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Introduce a new utility, preserve, which can be used to wrap any command that produces a single output file to ensure that the file is untouched unless the output has genuinely changed.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 50666
Build 47557: arc lint + arc unit

Event Timeline

des requested review of this revision.Mar 29 2023, 5:58 PM
jrtc27 added inline comments.
usr.bin/preserve/preserve.c
86

I would expect a vflag-guarded message here

196

This loses the fact that the child was signalled.

212

Why exit rather than return?

usr.bin/preserve/preserve.c
196

Kind of. The exit status will still be 128 + signal. Getting it 100% right is depressingly difficult.

212

Why return rather than exit?

usr.bin/preserve/preserve.c
86

Good catch. Note that this shouldn't occur though, unless we lost a race.

des marked an inline comment as done.Mar 29 2023, 6:34 PM

Try to deal with signals.

des marked an inline comment as done.Mar 29 2023, 6:39 PM
des marked an inline comment as done.

I have wanted a utility that does exactly this. install -C does something similar, but has other stuff I don’t want. So far I just end up scripting cmp(1) to do the check.

Would it make sense to add a -o flag to cmp(1) to provide this behavior there? It would write file1 to file2 if the contents differ.

Would it make sense to add a -o flag to cmp(1) to provide this behavior there? It would write file1 to file2 if the contents differ.

I don't think so. It wouldn't let you do make TOOL="preserve tool" like this does.