Axosoft / nsfw

A super fast and scaleable file watcher that provides a consistent interface on Linux, OSX and Windows
MIT License
902 stars 114 forks source link

Renaming a file does not returns "RENAMED" (3) action #78

Open andersr opened 5 years ago

andersr commented 5 years ago

When renaming a file, no RENAMED (3) action is returned. Instead a MODIFIED (2) action and a DELETED (1) action is returned.

events:  [
  {
    action: 2,
    directory: '/Users/andersjramsay/dev/testing_project/ctf_test_project/src',
    file: 'initialFOO.ts'
  },
  {
    action: 1,
    directory: '/Users/andersjramsay/dev/testing_project/ctf_test_project/src',
    file: 'initial.ts'
  }
]

I created a minimal repo which reproduces the above: https://github.com/andersr/filewatcher-test Running on OSX, using Node v12.4.0

mikejav commented 5 years ago

I'm very discouraged because of this problem. I just wanted to use nsfw for rename detection. I'm currently using a workaround where I observe on creating a file and then watch for deleting with tiny timeout. It seems that the rename works in this way on any system.

this.watcher.onDidCreate((createdFileUri) => {
  const onDeleteWatcher = this.watcher.onDidDelete((deletedFileUri) => {
    // my onRename handler
  });
  setTimeout(() => {
    onDeleteWatcher.dispose();
  }, 100);
});

Above example uses VS Code built in FileSystemWatcher.