Skip to content

Expressions with multiple -user predicates are broken or incompatible with GNU find #155

Closed

Description

@intelfx
$ bfs -not \( -user operator -or -user smb \) -exec ls -lad {} \; | tail -n1
bfs: warning: bfs -not "(" -user operator -or -user smb ")" -exec ls -lad "{}" ";"
bfs: warning:                                 ~~~~~~~~~
bfs: warning: This expression is always false.

-rw-rw----+ 1 smb smb 22057241 Oct 15  2024 ./Updates/10.21H2.x64/windows10.0-kb5045523-x64_e95ca9f3a548d05671f7be2ed034cf250d60d8ea.cab

Distributing the negation results in the same problem:

$ bfs \( -not -user operator -and -not -user smb \) -exec ls -lad {} \; | tail -n1
bfs: warning: bfs "(" -not -user operator -and -not -user smb ")" -exec ls -lad "{}" ";"
bfs: warning:                                       ~~~~~~~~~
bfs: warning: This expression is always false.

-rw-rw----+ 1 smb smb 819500057 Oct 15  2024 ./Updates/11.22H2.x64/windows11.0-kb5044285-x64_0879eebfa8d66123e40f2c2614bcfd16d053abe3.msu

I acknowledge that bfs' warning is self-consistent with the results, so it might be intended behavior rather than a bug, but I don't see why.

Equivalent command line works with GNU find as intuitively expected.

Activity

  1. tavianator commented on Jun 20, 2025

    @tavianator
    Owner

    I'm very sorry about this bug, and I'm sorry I didn't see it until now! I somehow missed the initial GitHub notification.

    This is a horrible bug that's been around since bfs 2.0, almost 5 years ago. It's caused by the optimizer assuming that

    • If -user operator is true, -nouser is false (correct)
    • If -user operator is false, -nouser is true (INCORRECT!)

    This leads to the invalid removal of -user smb, because the optimizer thinks it can't be true at the same time as -nouser (which is a valid optimization, but -nouser was wrongly inferred). A similar bug exists for -group and -nogroup.

    This bug is fixed in bfs 4.0.8 (release in progress). You can work around it in older versions with

    $ bfs -O0 -not \( -user operator -or -user smb \) -exec ls -lad {} \; | tail -n1
    

    to disable the optimizer. -O1 works too. It's broken at -O2 and above.

    Thank you very much for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions