node-inotify icon indicating copy to clipboard operation
node-inotify copied to clipboard

Wrong watch descriptor inside IN_DELETE_SELF

Open digitalnature opened this issue 10 years ago • 3 comments

It looks like this event's object holds the watch descriptor associated with the parent directory, not for the directory that was just deleted. Basically it returns the same data as IN_DELETE

digitalnature avatar Jan 27 '15 22:01 digitalnature

hm weird, any code to reproduce?

c4milo avatar Feb 02 '15 04:02 c4milo

@digitalnature are you still seeing this behavior?

c4milo avatar May 05 '15 00:05 c4milo

Hey, sorry for the late response, I didn't get the chance to look into this again.

So I made a little script trying to reproduce the issue:

var Inotify = require('inotify').Inotify;
var fs = require('fs');
var ino = new Inotify();

var path1 = __dirname + '/a';
var path2 = __dirname + '/a/b';


var test = function(event){
  var mask = event.mask;
  if(mask & Inotify.IN_Q_OVERFLOW)
    console.log('event queue overflow');

  if(mask & Inotify.IN_IGNORED)
    console.log('watch removed, WD = ' + event.watch);

  if(mask & Inotify.IN_DELETE_SELF)
    console.log('delete_self, WD = ' + event.watch);

  if(mask & Inotify.IN_DELETE)
    console.log('delete, WD = ' + event.watch);

};

var wm = Inotify.IN_CREATE | Inotify.IN_DELETE | Inotify.IN_DELETE_SELF | Inotify.IN_MODIFY | Inotify.IN_CLOSE_WRITE | Inotify.IN_MOVE_SELF | Inotify.IN_MOVED_FROM | Inotify.IN_MOVED_TO;

fs.mkdirSync(path1);
ino.addWatch({ path: path1, watch_for: wm, callback: test });  // wd = 1

fs.mkdirSync(path2);
ino.addWatch({ path: path2, watch_for: wm, callback: test });  // wd = 2

setTimeout(function(){
  console.log('Removing sub dir...');  
  fs.rmdirSync(path2);
}, 1000);

setTimeout(function(){
  fs.rmdirSync(path1);
  ino.close();
  process.exit();  
}, 2500);

but here the event for IN_DELETE_SELF doesn't fire at all. Weird, because in the app that I'm working on I get it, but with the wrong wd. Perhaps it has something to do with the number of watches?

digitalnature avatar May 07 '15 13:05 digitalnature