Page MenuHomeFreeBSD

find: implement -fprint and -fprint0
AcceptedPublic

Authored by imp on Nov 18 2023, 5:36 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 26, 3:15 PM
Unknown Object (File)
Mon, Nov 25, 7:56 PM
Unknown Object (File)
Nov 10 2024, 7:26 PM
Unknown Object (File)
Oct 24 2024, 12:27 PM
Unknown Object (File)
Oct 4 2024, 8:22 PM
Unknown Object (File)
Oct 3 2024, 9:37 PM
Unknown Object (File)
Oct 1 2024, 11:26 AM
Unknown Object (File)
Oct 1 2024, 5:48 AM

Details

Summary

Implement -fprint fn which will print the matching files to fn, each
followed by a newline ('\n'). And -fprint0 (same, except followed by a
NUL). Both of these are always true. The file is created if it does not
exist, or truncated if it does. This is done first thing
unconditionally, so if there's no output, the file will have zero
length.

Sponsored by: Netflix

Diff Detail

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

Event Timeline

imp requested review of this revision.Nov 18 2023, 5:36 AM
imp created this revision.
usr.bin/find/function.c
878

I suppose this output operation needs error checking (write an error message to stderr, make sure the exit status is not 0 and (whatever GNU find does) either stop immediately or continue without writing anything more to this file. Also, there probably should be fclose with error checking before exiting (near or in finish_execplus).

By the way, GNU find does not flush -fprint files when executing subprocesses unless it's -fprint for /dev/stdout or /dev/stderr, so we shouldn't either (it slows down things).

892

This means that multiple -fprint primaries to the same file will typically not work properly. I'm not sure we care. GNU find seems to concatenate all such output together, even if the -fprint primaries contain different hard links to the same file.

imp marked an inline comment as done.

fix man page...
Still contemplating what to do about the other feedback, but this is easy.

usr.bin/find/function.c
878

I'll take a look at what they do... We shouldn't flush fprintf either...
I'm not sure I follow about first error closing the file with checking... Please elaborate on why that's a good idea or the thinking behind it... it would be good to have in a comment and something better than 'imitate what gnu find does' would be ideal.

892

Hmmm... that's a bit surprising if true. I'll double check gnu find's behavior... multiple -fprints seems a bit odd... But maybe not too odd...

This revision is now accepted and ready to land.Dec 21 2023, 11:05 PM