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)
Sun, Nov 17, 2:00 AM
Unknown Object (File)
Thu, Nov 14, 1:03 PM
Unknown Object (File)
Sat, Nov 9, 6:11 AM
Unknown Object (File)
Fri, Nov 8, 6:32 PM
Unknown Object (File)
Fri, Nov 8, 2:59 AM
Unknown Object (File)
Mar 25 2024, 3:56 PM
Unknown Object (File)
Mar 19 2024, 5:53 AM
Unknown Object (File)
Feb 21 2024, 11:10 PM

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