gaze icon indicating copy to clipboard operation
gaze copied to clipboard

Folder deletion not catched

Open floz opened this issue 11 years ago • 10 comments

Hi,

Here is my project folder:

/app
/folder
  /node_modules
    /gaze
  - index.js

I'm having this code (folder/index.js):

var gaze = require( "gaze" )
,   path = require( "path" )
;
gaze( "app/**/*", function( err, watcher ) {
    console.log( "ERROR", err );

    this.on( "changed", function( filepath ) {
        console.log( filepath, "was changed" );
    });

    this.on( "added", function( filepath ) {
        console.log( filepath, "was added" );
    });

    this.on( "deleted", function( filepath ) {
        console.log( filepath, "was deleted" );
    });

    this.on( "all", function( e, filepath ) {
        console.log( filepath, "was", e );
    });

    console.log( this.relative() );
});

I'm executing it:

node folder/index.js

Then the script is running. I'm adding "foo.js" in /app. Everything is logged correctly. I'm adding a folder "toto" in /app. Everything is logged correctly. I'm removing "toto". Nothing is logged. I'm adding "bar.js" in /app. It crashes:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: watch ENOENT
    at errnoException (fs.js:1019:11)
    at FSWatcher.start (fs.js:1051:11)
    at Object.fs.watch (fs.js:1076:11)
    at Gaze._watchDir (/Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/component-app/node_modules/gaze/lib/gaze.js:289:30)

It appears that "toto" is still being watched. But when the file "bar.js" is created, "toto" is not find in app/ and generate a crash.

Am I doing something wrong or is this a bug?

Thanks!

floz avatar Apr 01 '14 18:04 floz

Could you try with the master branch (the next version)? npm install shama/gaze. This should be fixed there.

shama avatar Apr 01 '14 18:04 shama

I confirm, it works with your master branch version! However, it fires in the "all" events, with this: /Users/florian.zumbrunn/.Trash/toto 14-55-23-833 -- was renamed The deleted event never seems to be fired (I guess that's because the path is not the same as the initial -non deleted- file). Is that something planned for the future?

Note: This issue applies for both files & folders.

floz avatar Apr 01 '14 18:04 floz

Oh interesting. Technically the file is being renamed if moved into the trash as opposed to deleted, right? Do you get a deleted event if you rm toto from the terminal?

shama avatar Apr 01 '14 19:04 shama

Hmmm, yes that's the good explanation of the renaming/deleting problem :)

Yes I got one:

/Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/toto/ was deleted
/Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/toto/ -- was deleted

(the second line is from the "all")

My previous issue is happening when I right click/delete folder from sublime text. Strange thing, haha... !

floz avatar Apr 01 '14 19:04 floz

Via sublime text (right click/delete on the file):

_trigger, event: change /Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/
_trigger, newFile 
_trigger, event: rename /Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/toto.js
_trigger, newFile /Users/florian.zumbrunn/.Trash/toto 15-54-05-175.js
emit renamed
/Users/florian.zumbrunn/.Trash/toto 15-54-05-175.js -- was renamed

Via console (rm):

_trigger, event: delete /Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/toto.js
_trigger, newFile null
emit deleted
_trigger, event: change /Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/
_trigger, newFile 
/Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/toto.js was deleted
/Users/florian.zumbrunn/Documents/floz/works/projects/component_test/tools/app/toto.js -- was deleted

floz avatar Apr 01 '14 19:04 floz

This is working and can be closed right?

shama avatar Apr 13 '14 05:04 shama

Closing as it's expected to have renamed fired when a file is moved to the trash as opposed to deleted. Please reopen if there is still an issue. Thanks!

shama avatar Apr 15 '14 20:04 shama

My bad for the no answer. But I still think that's an issue. Gaze should say that the file is deleted, and not renamed, in the case the file path change to the trash. Don't you think?

Otherwise it would mean we need to implement it in the code of the tools based on gaze...

floz avatar Apr 15 '14 21:04 floz

kqueue, the native OS library, considers moving a file to the trash a renamed event. I would have to do special handling in gaze to change the event to a deleted.

I think going with technically correct is the best solution here and technically we are not deleting a file, we are moving it to another location on the file system, which just happens to be the trash.

shama avatar Apr 15 '14 22:04 shama

So apparently I am the minority considering moving a file to the trash a renamed event. So if someone wants to send a patch to make moving a file to the trash considered a deleted in a sane way, I'll be happy to merge it.

shama avatar Apr 16 '14 18:04 shama