watcher icon indicating copy to clipboard operation
watcher copied to clipboard

Undo from finder/explorer does not report file events

Open bpasero opened this issue 1 year ago • 3 comments

Steps:

  • setup parcel watcher according to docs, simply watching a folder [1]
  • create a sub-folder in that watched folder
  • create a file in that sub-folder
  • from the finder (macOS) or explorer (Windows) delete the sub-folder
  • => you get a delete event for that folder
  • undo the operation from the finder / explorer
  • => you get a create event but only for the folder, not for the files within

[1]

const watcher = require('@parcel/watcher');
const path = require('path');

async function main() {
    // Subscribe to events
    let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
        console.log(events);
    });

   
}

main();

bpasero avatar Aug 28 '24 08:08 bpasero

I think that's because when you delete a file, it only moves it to the trash. Then when you undo, it moves it back. So actually macOS delivers a rename event in that case. Not sure there's anything we could do about that short of traversing the entire directory ourselves. But you could also do that in user land - whenever a directory is created assume it might contain children. Do any other watcher libraries handle this?

devongovett avatar Aug 30 '24 20:08 devongovett

Maybe rename events could be emitted by parcel watcher in case the underlying OS library supports it?

bpasero avatar Aug 31 '24 05:08 bpasero

It also happens when we rename a folder which contains some files. Watcher fires a create event for the new folder only (no event are fired for the files inside)

treoden avatar Jun 17 '25 12:06 treoden