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, May 7, 3:15 AM
Unknown Object (File)
Thu, May 2, 1:36 PM
Unknown Object (File)
Mon, Apr 29, 3:36 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
Unknown Object (File)
Jan 28 2024, 8:21 PM
Unknown Object (File)
Jan 28 2024, 7:54 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