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

When renaming file, is a create event fires for the old filename (Windows) #26

Open
dasmikko opened this issue Jun 28, 2017 · 7 comments

Comments

@dasmikko
Copy link

using Node 8.0.0

What i'm doing:
Renaming a file from file2.txt -> file3.txt

What happens
2 events fire:
a rename event, and a create event for the old filename,

Events:

changes { action: 3,
  directory: 'C:\\Users\\Mikkel\\Desktop\\Watchthis\\customer',
  oldFile: 'file2.txt',
  newFile: 'file3.txt' }
-----------------
changes { action: 0,
  directory: 'C:\\Users\\Mikkel\\Desktop\\Watchthis\\customer',
  file: 'file2.txt' }

I'm pretty sure that this is not what we want. :)

@implausible
Copy link
Contributor

Bizarre! Will try to repro.

@dasmikko
Copy link
Author

dasmikko commented Jun 28, 2017

If it helps, I'm using your second example.

@dasmikko
Copy link
Author

Any update on this?

@rooksack
Copy link

rooksack commented Jul 6, 2018

Sorry that I must bring this issue up again. I am using Win 7 and Node v6.11.0 and on all rename Operations the actions "rename" and "create" are fired. I tracked the problem down to nsfw/src/win32/Watcher.cpp around Line 209
... switch (info->Action) { case FILE_ACTION_ADDED: case FILE_ACTION_RENAMED_NEW_NAME: // in the case we just receive a new name and no old name in the buffer mQueue->enqueue(CREATED, getUTF8Directory(fileName), getUTF8FileName(fileName)); break; case FILE_ACTION_REMOVED:..

If i rename a file - the events FILE_ACTION_RENAMED_OLD_NAME and FILE_ACTION_RENAMED_NEW_NAME are fired. Could you explain the case where only FILE_ACTION_RENAMED_NEW_NAME is fired ?

thanks in advance

@norswap
Copy link

norswap commented Sep 2, 2018

I have the issue as well.

As a stopgap, here is a function I use to eliminate these annoying events, as well as de-duplicate events, and parasitic MODIFIED events on freshly renamed files:

function debounce (events)
{
    const map = {}
    // eliminate duplicate events
    events.forEach(it => map[JSON.stringify(it)] = it)

    for (event of Object.values(map))
    {
        // On Windows (at least), renames will cause a creation event on the old
        // file. Here we delete it. (https://github.com/Axosoft/nsfw/issues/26)
        // It also generates a modify event on the the new file, which we also
        // delete.
        if (event.action == watcher.actions.RENAMED) {
            const create_old = {
                action: watcher.actions.CREATED,
                directory: event.directory,
                file: event.oldFile
            }
            const modify_new = {
                action: watcher.actions.MODIFIED,
                directory: event.directory,
                file: event.newFile
            }
            delete map[JSON.stringify(create_old)]
            delete map[JSON.stringify(modify_new)]
        }
    }

    return Object.values(map)
}

@nono
Copy link
Contributor

nono commented Oct 25, 2018

I also reproduce this issue on Windows 10 (a free Virtual Machine from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/), with node 8.12.0 and using the master branch:

$ nsfw -v C:\Users\IEUser\Desktop\Current
renamed: C:\Users\IEUser\Desktop\Current\foo → bar
Created: C:\Users\IEUser\Desktop\Current\foo
Modified: C:\Users\IEUser\Desktop\Current\bar

@MMhunter
Copy link

Any updates on this issue?

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

Successfully merging a pull request may close this issue.

6 participants