Watchman: ignore/exclude directory in watchlist not work

Created on 18 May 2019  路  13Comments  路  Source: facebook/watchman

I have configured the watchman 4.9.4 on Ubuntu and its working fine.

For Directory exclude/Ignore I have done the setting like below but it didn't exclude the directory

cat state
{
"watched": [
{
"triggers": [
{
"command": [
"/home/niraj/watchjson.sh"
],
"append_files": true,
"name": "jsontest",
"ignore_dirs": [
"/home/niraj/jsontest/ignore"

],
"stdin": [
"name",
"exists",
"new",
"size",
"mode"
]
}
],
"path": "/home/niraj/jsontest"
},
],
"version": "4.9.4"
}

As its not work then I added the .watchmanconfig

{
"ignore_dirs": ["/home/niraj/jsontest/ignore"]
}

but its not work. Please guide how can I exclude directory/files.

Most helpful comment

How many files are likely to be in the upload folder? How frequently are they created and deleted?
If the volume and rate of change is relatively low, then you don't need to use ignore_dirs and can instead exclude matching paths in your trigger query expression:

$ watchman -j <<-EOT
["trigger", "/home/niraj/jsontest", {
  "name": "jsontest",
  "expression": ["not", ["match", "upload/**", "wholename"]],
  "command": ["/home/niraj/watchjson.sh"],
  "stdin": ["name"],
}]
EOT

All 13 comments

The paths must be relative to the watched root:

{
   "ignore_dirs": ["ignore"]
}

Dear Wez,
Thank you. Its seems to work when configure in .watchmanconfig.

I want to set this in Json file and its not working. Please guide how to define this on my json file.

I have bold the Entry above that I have added in my json file.

The state file is not meant to be something that you edit by hand. If you want watchman to ignore a directory then it must be specified in the .watchmanconfig file as I indicated above.

What is your higher level goal? What is it that you want to use watchman for?

Dear Wez,

My goal is I have nextcloud snap it has multiple users when any users upload files or modify files it should be backup to other location. Everything seems to work. I am not using the STATE file watching directory instead I have made my own json file and run it by this command
watchman -j < jsonfile
Problem is here I have to add the .watchmanconfig file on every users home. if any method to add this ignore_dirs in that json file so I need to maintain only that json file. My Json file is here so I can add here the multiples user's directory for watch. This file is only sample file.
["trigger", "/home/niraj/jsontest", {
"name": "jsontest",
"stdin": [
"name",
"exists",
"new",
"size",
"mode"
],
"command": ["/home/niraj/watchjson.sh"],
"append_files": true
}]

So Please guide If you have any idea to achieve the same.

We don't have that sort of functionality today.
https://github.com/facebook/watchman/issues/202 is an issue that raises the idea of making this sort of configuration more flexible, but we don't have a burning need for this and thus haven't implemented it.

Do you really need to use ignore_dirs? Can you tell me more about what you want to ignore? That might help me suggest alternative options.

In Nextcloud when you upload, the upload size is supposed 100 MB. then it creates a chunks of 10 MB in upload folder. 100 MB size so it will create 10 MB 10 chunks that is not required to be sync.
so this directory upload need to be ignore as its used for chunks data only.

How many files are likely to be in the upload folder? How frequently are they created and deleted?
If the volume and rate of change is relatively low, then you don't need to use ignore_dirs and can instead exclude matching paths in your trigger query expression:

$ watchman -j <<-EOT
["trigger", "/home/niraj/jsontest", {
  "name": "jsontest",
  "expression": ["not", ["match", "upload/**", "wholename"]],
  "command": ["/home/niraj/watchjson.sh"],
  "stdin": ["name"],
}]
EOT

Hi @wez and @nirajvara I am experiencing a similar issue. Our use case is a medical DICOM server where we need to watch folders and trigger certain scripts for each patient image created / edited in watched folder.

Adding "ignore_dirs" directive in local .watchmanconfig file works as intended, but copy-pasting the same directive in global /etc/watchman.json file does not work.

How many files are likely to be in the upload folder? How frequently are they created and deleted?
If the volume and rate of change is relatively low, then you don't need to use ignore_dirs and can instead exclude matching paths in your trigger query expression:

$ watchman -j <<-EOT
["trigger", "/home/niraj/jsontest", {
  "name": "jsontest",
  "expression": ["not", ["match", "upload/**", "wholename"]],
  "command": ["/home/niraj/watchjson.sh"],
  "stdin": ["name"],
}]
EOT

Hi

I tried the above expression but its works only when file modification is there. means only ignore the file
modification but when created a new file in /upload, expression is not working.

@wez Figured it out based on your example above, thanks!

PS: (Suggestion in issue #463 might be a good idea as Watchman usage grows.)

I have the same problem. I need to exclude/ignore a .ssh directory in my watched root, which is /home/myuser/, so I added to the /home/myuser/.watchmanconfig file, the following lines:

{
"ignore_dirs": [".ssh"]
}

But Watchman keeps executing the trigger for this directory.

Please try this

"expression": ["allof",
["match", ""],
["not", ["match", ".ssh/
*", "wholename"]]

For those landing with similar issue try this

Check if watchman reads you config correctly
watchman get-config .

If it didn't read it restart the daemon via
watchman shutdown-server

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rahulk8 picture rahulk8  路  5Comments

seenickcode picture seenickcode  路  5Comments

ACoolmanBigHealth picture ACoolmanBigHealth  路  4Comments

yangzhichina picture yangzhichina  路  5Comments

rongliangduan picture rongliangduan  路  3Comments