Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename raw event breaks further events #591

Closed
fdiogo opened this issue Mar 22, 2017 · 7 comments
Closed

rename raw event breaks further events #591

fdiogo opened this issue Mar 22, 2017 · 7 comments
Labels

Comments

@fdiogo
Copy link

fdiogo commented Mar 22, 2017

.watch seems to break when there's a 'rename' event on Linux and no more events are fired from there on.
Vim fires this on wq and Git on checkout, for example.

The current workaround I'm using seems to fix this:

this.watcher.on('raw', (event, path, {watchedPath}) => {
            if (event === 'rename') {
                this.watcher.unwatch(watchedPath);
                this.watcher.add(watchedPath);
            }
        });

It seems this might be easily patched out by verifying that the renamed file has the same name and re-attach the listener automatically.

@es128
Copy link
Collaborator

es128 commented Mar 28, 2017

Please provide a script or repo for demonstrating the problem. I suspect the cause is something different than just receiving a rename event from fs.watch().

@AndyOGo
Copy link

AndyOGo commented Apr 11, 2017

I observe a similar behaviour on my CI tests at Linux if an empty dir is deleted:
https://travis-ci.org/AndyOGo/node-sync-glob/jobs/220915572#L976

console.log src/index.js:242
    RAW: rename -> empty 	
    { watchedPath: 'tmp/mock/bar/empty' }

console.log src/index.js:242
    RAW: rename -> empty 	
    { watchedPath: 'tmp/mock/bar/empty' }

console.log src/index.js:242
    RAW: rename -> empty 	
    { watchedPath: 'tmp/mock/bar' }

 FAIL  test/sync.spec.js (13.696s)
  ● node-sync-glob watch › should sync empty sub directory deletion
    Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
      
      at ontimeout (timers.js:386:14)
      at tryOnTimeout (timers.js:250:5)
      at Timer.listOnTimeout (timers.js:214:5)

  node-sync-glob watch
    ✓ should sync a file (2135ms)
    ✓ should sync an array of files (2125ms)
    ✓ should sync a directory (2153ms)
    ✓ should sync globstar (2149ms)
    ✕ should sync empty sub directory deletion (5008ms)

@fxha
Copy link

fxha commented Mar 26, 2019

I also have this problem when editing a file which is watched. For example if you watch just a.txt and edit the file with gedit, only the first edit is triggered. I think the problem is the rename event and chokidar still listen on the old file. Gedit result:

raw: "change" "a.txt"
raw: "rename" "a.txt"
raw: "rename" "a.txt"
change: "%path%/a.txt"

Where as atom/watcher triggers the creation event. With other editors like vim or vscode everything works fine and further events are triggered:

raw: "change" "a.txt"
raw: "change" "a.txt"
change: "%path%/a.txt"

Listening the whole directory shows that gedit creates a temporary backup file and then just move the backup file:

created file: %path%/.goutputstream-VP92YZ
modified file: %path%/.goutputstream-VP92YZ
modified file: %path%/.goutputstream-VP92YZ
renamed file: "%path%/.goutputstream-VP92YZ" to "%path%/a.txt"

@pkit
Copy link
Contributor

pkit commented Apr 25, 2020

Cool, 2 years, no fix. Splendid!

@paulmillr
Copy link
Owner

@pkit Go ahead and fix it. No one pays me to do this.

pkit added a commit to pkit/chokidar that referenced this issue Apr 26, 2020
will re-add the watcher on inode change in `fs.watch` mode on Linux
the idea was shamelessly stolen from @paco3346

bonus: fixed strange, pretty infrequent race in `fs.watchFile` test case `should emit matching dir events`
pkit added a commit to pkit/chokidar that referenced this issue Apr 26, 2020
will re-add the watcher on inode change in `fs.watch` mode on Linux
the idea was shamelessly stolen from @paco3346

bonus: fixed strange, pretty infrequent race in `fs.watchFile` test case `should emit matching dir events`
pkit added a commit to pkit/chokidar that referenced this issue Apr 26, 2020
will re-add the watcher on inode change in `fs.watch` mode on Linux
the idea was shamelessly stolen from @paco3346

bonus: fixed strange, pretty infrequent race in `fs.watchFile` test case `should emit matching dir events`
@pkit
Copy link
Contributor

pkit commented Apr 26, 2020

@paulmillr it would have more contributors if the tests were not failing left and right on unrelated things.

pkit added a commit to pkit/chokidar that referenced this issue Apr 26, 2020
will re-add the watcher on inode change in `fs.watch` mode on Linux
the idea was shamelessly stolen from @paco3346

bonus: fixed strange, pretty infrequent race in `fs.watchFile` test case `should emit matching dir events`
pkit added a commit to pkit/chokidar that referenced this issue Apr 26, 2020
will re-add the watcher on inode change in `fs.watch` mode on Linux
the idea was shamelessly stolen from @paco3346

bonus: fixed strange, pretty infrequent race in `fs.watchFile` test case `should emit matching dir events`
pkit added a commit to pkit/chokidar that referenced this issue Apr 26, 2020
will re-add the watcher on inode change in `fs.watch` mode on Linux
the idea was shamelessly stolen from @paco3346

bonus: fixed strange, pretty infrequent race in `fs.watchFile` test case `should emit matching dir events`
@paulmillr
Copy link
Owner

@pkit see #923, fixing failing tests is not a simple task.

pkit added a commit to pkit/chokidar that referenced this issue Apr 27, 2020
will re-add the watcher on inode change in `fs.watch` mode on Linux

bonus: fixed strange, pretty infrequent race in `fs.watchFile` test case `should emit matching dir events`
paulmillr added a commit that referenced this issue Apr 28, 2020
add `safe-edit` handling for Linux, fixes #591
personalizedrefrigerator added a commit to personalizedrefrigerator/joplin that referenced this issue Jul 3, 2024
Removes an obsolete workaround fix for
paulmillr/chokidar#591. This seems to fix
external editing with Vim.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants