chokidar icon indicating copy to clipboard operation
chokidar copied to clipboard

change event doesn't work after unlink

Open qarlosalberto opened this issue 1 year ago • 1 comments
trafficstars

Describe the bug

When I remove a file the unlink event is called. After that the change event doesn't work when I recreate the file

Versions:

  • Chokidar version 3.5.3
  • OS version: Ubuntu 22.04

qarlosalberto avatar Nov 26 '23 10:11 qarlosalberto

It works on the latest (3.6.0) version.

ah-naf avatar May 23 '24 05:05 ah-naf

I can confirm it's not working reliable. We use version 3.6.0. Most of the time add/change events don't get fired when they occur immediately after the unlink event. OS: Windows 11.

Tested with following code:

import { dirname } from 'path';
import { existsSync } from 'fs';
import { FSWatcher } from 'chokidar';
import { exit } from 'process';

const handleEvent = (path) => {
  console.log('event handled');
};

const fsWatcher = new FSWatcher({
    ignorePermissionErrors: true,
    ignoreInitial: true,
    awaitWriteFinish: {
        stabilityThreshold: 1000,
        pollInterval: 100,
    },
});

fsWatcher.on('all', (eventName, path) => {
    console.log(`fired event ${eventName}`);
    if (eventName === 'add' || eventName === 'change') {
        handleEvent(path);
    }
});

const filePath = '/Users/xxx/import/import.txt';
const parentDir = dirname(filePath);

if (!existsSync(parentDir)) {
    console.log(`will not start watching ${filePath}. parent directory ${parentDir} does not exist`);
    exit(1);
}

fsWatcher.add(filePath);
console.log('watching ' + filePath);

ajgassner avatar Jun 17 '24 08:06 ajgassner