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

Issue with Renaming Nested Files #664

Closed
MichaelEPope opened this issue Jan 6, 2018 · 1 comment
Closed

Issue with Renaming Nested Files #664

MichaelEPope opened this issue Jan 6, 2018 · 1 comment

Comments

@MichaelEPope
Copy link

MichaelEPope commented Jan 6, 2018

Hey, I just noticed a small issue with renaming files. I think it might be my error, but just in case it isn't, I thought I'd post it. Perhaps someone can test it on their system and see if they are getting the same results.

I'm running on 64-bit Windows 10. I have not tested it on other operating systems (sorry =/).

The steps I take to cause the error are the following.

  1. Watch the current directory with chokidar (the error appears even if you don't watch the current directory, but for the simplicity of testing, let's say it's the current one).
  2. Create a folder in that directory. We'll call that Created_Folder_1.
  3. Create another folder inside of that folder. We'll call that Created_Folder_2.
  4. Attempt to rename Created_Folder_1.
  5. You should see a Windows prompt saying that a program is currently using the folder and so it can't be renamed (if you are using an IDE like VSCode, it may not show that error, but in both cases, the file can't be renamed, and no add or unlink event is thrown by chokidar).

Here's the file I use in order to test this:

const chokidar = require('chokidar');

var ready = false;

const watcher = chokidar.watch('.', {ignored: /node_modules.*/});
watcher.once('ready', function()
{
    ready = true;
});
watcher.on('add', function(path)
{
    if(ready)
    {
        console.log('add', path);
    }
    else
    {
        console.log('add-pre-init', path);
    }
});
watcher.on('change', function(path, stats)
{
    if(ready)
    {
        console.log('change', path, stats);
    }
    else
    {
        console.log('change-pre-init', path, stats);
    }
});
watcher.on('unlink', function(path)
{
    if(ready)
    {
        console.log('unlink', path);
    }
    else
    {
        console.log('unlink-pre-init', path);
    }
});
watcher.on('addDir', function(path)
{
    if(ready)
    {
        console.log('addDir', path);
    }
    else
    {
        console.log('addDir-pre-init', path);
    }
});
watcher.on('unlinkDir', function(path)
{
    if(ready)
    {
        console.log('unlinkDir', path);
    }
    else
    {
        console.log('unlinkDir-pre-init', path);
    }
});
watcher.on('error', function(err)
{
    console.log('error', err);
});


module.exports = {}

Here's the error that I see if I do it from the regular File Explorer UI:

image

If you do it in VSCode there is no immediate error, but the rename is not accepted.

image

Eventually though an error appears:

image

This does not effect non-nested files at all. So I could renamed Created_Folder_2 with no problems.

image

Thanks for your help on this. And I hope this post provided enough info... it's my first time doing this. :)

@MichaelEPope MichaelEPope changed the title Issue with Renaming Files Issue with Renaming Nested Files Jan 6, 2018
@es128
Copy link
Contributor

es128 commented Jan 9, 2018

It's a known quirk of the Windows API for file watching, as exposed by the node.js core method fs.watch(). You could try setting the usePolling: true option in chokidar to switch to watching based on stat polling as provided by fs.watchFile(), although there is a performance penalty. Your watch target seems relatively small, so you may not notice the difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants