Skip to content

Document "?" file type #892

Open
Open

Description

@bitc

The documentation lists the available file types: https://facebook.github.io/watchman/docs/expr/type.html

But it is missing the type: ?

You can see this type being returned in the source code here: https://github.com/facebook/watchman/blob/e881968070e43d28111e73ac67958256f3e8a09d/query/fieldlist.cpp#L256

This affected me in production because I wasn't expecting to get "?" (because it's undocumented).

Btw, I got a "?" result in Linux for a vim swap file.

Activity

  1. genevievehelsel commented on Feb 16, 2021

    @genevievehelsel
    Contributor

    Thanks for pointing this out! I've just added documentation for this case, it should be pushed soon :)

  2. bitc commented on Feb 17, 2021

    @bitc
    Author

    Thanks. I actually received "?" from watchman for a vim swap file (not a "whiteout"). I'm not sure why the file isn't reported as a regular file, maybe it's some other bug.

  3. wez commented on Feb 17, 2021

    @wez
    Contributor

    Could you share the output from stat /path/to/that/file so that we can see exactly what its st_mode bits look like?

  4. bitc commented on Feb 17, 2021

    @bitc
    Author

    I think I figured out the bug. vim creates a file and then immediately renames it. watchman seems to have trouble with this.

    I tried to reproduce with a shell script (touch file1; mv file1 file2), but I think it is too slow (watchman correctly reports the operations)

    But this C script is able to cause watchman to fail:

    rename_test.c

    #include <stdio.h>
    #include <unistd.h>
    #include <fcntl.h>
    
    int main() {
        // Create new empty file
        FILE *fp = fopen("target_dir/file1", "w");
        fclose(fp);
    
        // Quickly rename it
        rename("target_dir/file1", "target_dir/file2");
    
        return 0;
    }
    $ gcc rename_test.c -o rename_test
    

    If I tell watchman to "subscribe" on the target directory, and then run rename_test inside it, I get this subscription event:

    [
      {
        "name": "file2",
        "exists": true,
        "type": "f",
        "size": 0
      },
      {
        "name": "file1",
        "exists": false,
        "type": "?",
        "size": 0
      }
    ]

    This is on Linux 4.15.0

  5. wez commented on Feb 17, 2021

    @wez
    Contributor

    Ok! "?" is really the "I have no idea what type this is" symbol that is used for the "impossible" case in that code (we'll fix up the docs to reflect that).

    You can expect to see that when exists == false because there is no current information about the file type when it doesn't exist.

  6. bitc commented on Feb 17, 2021

    @bitc
    Author

    Maybe in this case watchman should not report anything at all about "file1"? As far as the app is concerned, "file1" never existed, and it never received a "create" event for it, so why should it receive a "delete" event? I can't imagine a scenario where an app would have anything useful to do with this information.

  7. wez commented on Feb 17, 2021

    @wez
    Contributor

    watchman doesn't deliver delete events because that is not a guaranteed concept; the OS may not deliver a change event for a variety of OS dependent reasons and those events are highly prone to TOCTOU in any case.

    Instead of change events, Watchman delivers state updates based on the observed state in a given clock tick.

    It is reporting that file1 matches your query criteria for things that changed since an earlier clock value, and that its current state at that time is that it doesn't exist.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions