gruntjs / grunt-contrib-watch

Run tasks whenever watched files change.
http://gruntjs.com/
MIT License
1.98k stars 356 forks source link

Permission error is still thrown on exempted directory #517

Open mattkelsey opened 8 years ago

mattkelsey commented 8 years ago

Context: here is a problem I had a little while back. I had a grunt watch task like so:

watch: {
  express: {
    files: [
      'server/**/*.{js,json}',
      '!server/influx/**' //this should leave out the protected subdirs of influx (read below)
      //'!server/influx' -- this also didn't work
    ],
    tasks: ['express:dev', 'wait'],
    options: {
      livereload: true,
      nospawn: true
    }
  }
},

The directory server/influx was mounted as a volume in a docker container. This was important because it meant that its subdirectories were protected, grunt didn't have access. server/influx was not protected only the subdirectories (and all of their subdirs recursively).

When the watch task was run I received the following warning: Warning: EACCES: permission denied, scandir 'server/influx/data/_internal/monitor'

While this was just a warning it seemed to be halting grunt, none of my other tasks were being executed. With the --force option grunt seemed to skip the watch task, thus not running the express task and so nothing was getting served.

I had explicitly told my watch task to ignore all subdirectories in server/influx so it would seem that grunt should not have been trying to scan those directories.

Also neither express:dev or wait contained any wildcards or direct references to any of the subdirectories in server/influx and the error still occurred when those tasks were removed.

The (not optimal) solution to this was as follows:

watch: {
  express: {
    files: [
      'server/{api,components,config}/**/*.{js,json}' //note that this does not include server/influx only the other subdirs
    ],
    tasks: ['express:dev', 'wait'],
    options: {
      livereload: true,
      nospawn: true
    }
  }
},

It seems that if I explicitly state the subdirectories to look in rather than using a wildcard and exempting server/influx/** it works as expected with no permission warning thrown.

So I believe the issue is that when a wildcard is used to include all subdirectories and one is excluded, grunt will still throw permission errors on the excluded directory if it doesn't have access which can in some cases halt tasks.

I would like to be able to include all sub directories except for one that grunt will not have permissions to in order to suppress permission errors. This way if I add new directories I want grunt to watch in the future to server/ I won't have update my Gruntfile.