Axosoft/nsfw

too many duplicate events

Opened this issue · 5 comments

When doing a multiple file copy of a watched folder, many duplicate events are being generated.

{action: 0, directory: "watched_directory\dir1", file: "file1.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file1.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file1.ext"}
{action: 2, directory: "watched_directory", file: "dir1"}
{action: 0, directory: "watched_directory\dir1", file: "file2.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file2.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file2.ext"}
{action: 2, directory: "watched_directory", file: "dir1"}
{action: 0, directory: "watched_directory\dir1", file: "file3.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file3.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file3.ext"}
{action: 2, directory: "watched_directory", file: "dir1"}
{action: 0, directory: "watched_directory\dir1", file: "file4.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file4.ext"}
{action: 2, directory: "watched_directory\dir1", file: "file4.ext"}
{action: 2, directory: "watched_directory", file: "dir1"}

Would it be much wiser if before adding a change event to the queue first a check is done if it is already in it @implausible ?

So that we don't have to dedupe all the events first before processing?

After further investigation, it seems the route cause on Windows seems to be FILE_NOTIFY_CHANGE_LAST_ACCESS flag.

This causes a change event on each file read ... is this really desired? As there is really nothing changed - file is just "accessed"

Maybe we should just remove this flag @implausible or an an option for it?

Is this also Windows only? Seems that on MacOS at least no change events are triggered when file is just accessed.

A as similar issue with the node watch code: nodejs/node#21643 (comment)

Awesome sleuthing. Let's go ahead and remove that flag. I agree, that is not something that we need to track. If we see push back we can course correct with an option.

It is maybe worth mentioning that the default C# file system watcher uses these flags:

https://github.com/dotnet/runtime/blob/6b11f64ec09983013862c2fd85ba29c940c44eea/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs#L29

NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName

We have been using these flags for a long time on Windows in VSCode without issues. In our (new) fork of nsfw, we pushed this commit:

https://github.com/microsoft/vscode-nsfw/commit/97c11885bd03d36f5c6286b8bdbfbc1ec649f295

PR: #147

This seems to be happening still.