paulmillr / chokidar

Minimal and efficient cross-platform file watching library

Home Page:https://paulmillr.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'addDir' event is fired twice when file's name capitalization changes on MacOS

tomaszczura opened this issue · comments

Describe the bug

addDir event is fired twice when I change file's name capitalization, e.g. from Folder A to folder a - first event comes with Folder A, and the second with folder a

Versions (please complete the following information):

  • Chokidar version [3.5.3]
  • Node version [16.14.2]
  • OS version: [Mac OS 12.6 Monterey]

To Reproduce:

Steps to reproduce the behavior. Include filename and chokidar config.

Ideally prove a problem by isolating and making it reproducible with a very short sample program, which you could paste here:

import chokidar, { FSWatcher } from 'chokidar';
import fs from 'fs'

const watcher = chokidar.watch('./', {
	ignoreInitial: true,
})

watcher
.on('addDir', (addedPath) =>  console.log("ADDED:", addedPath))
.on('change', (changedPath) => console.log("CHANGED", changedPath))

if (!fs.existsSync('./myFolder')) {
	fs.mkdirSync('./myFolder');
}

setTimeout(() => {
	console.log("Change folder name");
	fs.renameSync('./myFolder', './myfolder');

	setTimeout(() => {
		console.log("Closing...")
		watcher.close();
		fs.rmSync('./myfolder', { force: true, recursive: true })
	}, 5000)
	
}, 2000)

Actual behavior
The output is:

ADDED: myFolder
Change folder name
ADDED: myFolder <-- this event should not be there - the file was renamed and does not exist
ADDED: myfolder
Closing...

Expected behavior
Output should be:

ADDED: myFolder
Change folder name
ADDED: myfolder
Closing...

This is affecting me, too.