Giter Club home page Giter Club logo

node-pathwatcher's Introduction

Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our official announcement

Path Watcher Node module

ci Depenency Status

Installing

npm install pathwatcher

Building

  • Clone the repository
  • Run npm install to install the dependencies
  • Run npm test to run the specs

Using

PathWatcher = require 'pathwatcher'

PathWatcher.watch(filename, [listener])

Watch for changes on filename, where filename is either a file or a directory. The returned object is a PathWatcher.

The listener callback gets two arguments (event, path). event can be rename, delete or change, and path is the path of the file which triggered the event.

For directories, the change event is emitted when a file or directory under the watched directory got created or deleted. And the PathWatcher.watch is not recursive, so changes of subdirectories under the watched directory would not be detected.

PathWatcher.close()

Stop watching for changes on the given PathWatcher.

node-pathwatcher's People

Contributors

50wliu avatar abe33 avatar abnerlee avatar aminya avatar anaisbetts avatar anderoonies avatar benjamn avatar benogle avatar bolinfest avatar bradgearon avatar damieng avatar darangi avatar dbkaplun avatar ficristo avatar fornever avatar glasser avatar kevinsawicki avatar lwblackledge avatar magic890 avatar maxbrunsfeld avatar mnquintana avatar mostafaeweda avatar rafeca avatar sadick254 avatar smashwilson avatar ssorallen avatar termina1 avatar tomfreudenberg avatar tong avatar zcbenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-pathwatcher's Issues

Uncaught Error: EACCES, permission denied. // Idea: Maybe an enhancement.

Hey,

I guess it's not a bug but something which could definitely be enhanced.
While I got this error above I tried to modify a file which I created through the terminal via sudo, that means I shouldn't have the permission to do so. Sometimes Mac OS asks me for my password as the root user then. Do you have any idea for making this step more seamless?

It's a little bit wird because the console opens then and throws that error:
/Applications/Atom.app/Contents/Resources/app/node_modules/pathwatcher/lib/file.js:190
otherwise it would be a way you're used to when you modify files without permission on OS X.

Error on Mac OS X (10.9.2) and Node v0.10.13 without --harmony option

On Mac OS X (10.9.2) and Node v0.10.13, after installing the module using npm install pathwatcher, I got this error:

var path = require("pathwatcher")
ReferenceError: WeakMap is not defined
    at Behavior.module.exports.PropertyAccessors.lazyAccessor (/Users/samypesse/Desktop/Projects/testWatcher/node_modules/pathwatcher/node_modules/emissary/node_modules/property-accessors/lib/property-accessors.js:52:20)
    at /Users/samypesse/Desktop/Projects/testWatcher/node_modules/pathwatcher/node_modules/emissary/lib/behavior.js:70:24
    at Object.<anonymous> (/Users/samypesse/Desktop/Projects/testWatcher/node_modules/pathwatcher/node_modules/emissary/lib/behavior.js:116:5)
    at Object.<anonymous> (/Users/samypesse/Desktop/Projects/testWatcher/node_modules/pathwatcher/node_modules/emissary/lib/behavior.js:120:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)

It works fine using option --harmony. Is there a way to not be dependent on the --harmony option?

Linux support?

Thanks for this library! It works incredibly well and fast on OSX/Windows. But when trying to run on Ubuntu 12.04, I get the following error:

node: symbol lookup error: /home/kyle/Documents/www/gaze/node_modules/pathwatcher/build/Release/pathwatcher.node: undefined symbol: _Z12PlatformInitv

I'm using [email protected] and node.js 0.10.22. With the following test script:

var PathWatcher = require('pathwatcher');
var grunt = require('grunt');
var path = require('path');

var base = path.resolve(__dirname, 'tmp');
for (var i = 0; i < 99; i++) {
  grunt.file.write(path.join(base, 'file' + i, 'var test = true'));
}

grunt.file.expand('tmp/*').forEach(function(file) {
  PathWatcher.watch(file, function(event, filename) {
    console.log(event, file);
  });
});

setInterval(function() {
  var n = Math.floor(Math.random() * 99);
  var file = path.join(base, 'file' + n);
  if (n < 50) {
    grunt.file.delete(file);
  } else {
    grunt.file.write(file, 'var test = true');
  }
}, 1000);

[Windows] Change events do not fire when file is at drive root

If the file is at the drive root the change event in HandleWatcher.onEvent fires but it does not fire the change in the PathWatcher.onChange method because the path provided to HandleWatcher.onEvent contains \\, while the @path variable does not.

This has been observed on Windows 10 but does not occur on linux.

HandleWatcher replacement error handling logic is broken

7e10102 changed HandleWatcher.start to "Remove the old one if we found two same file handles" instead of throwing an exception.

Choosing to replace an existing HandleWatcher with a new one with just a logged error instead of throwing an exception might make sense. But the choice in that commit to call troubleWatcher.close() seems broken.

troubleWatcher.close() does two things: binding.unwatch, and handleWatchers.remove. The latter is reasonable: we're trying to replace the old bogus HandleWatcher with the new one, so we should remove it, sure.

But binding.unwatch here is problematic: the argument we're passing to it is just the fd that we got back from binding.watch, which we're going to pass to close (Mac) or inotify_rm_watch (Linux). But... that means we're actually closing the fd we just got back from binding.watch and which is saved in the new HandleWatcher!

ie, this error case means we've suddenly learned that a HandleWatcher in handleWatchers contains an invalid WatcherHandle (fd). Going and calling close on that invalid handle is just going to break the new thing we got.

Process taking 100% CPU on Windows

On my Windows configuration, pathwatcher starts taking up 100% CPU exhausting the node process. In the task manager it looks like the process of node is taking 99-100% CPU.

It doesn't happen on any set of observed files. I found a reproduction that consistently shows the problem on my machine (see the code below) and as I noticed, it is not a matter of a particular file path. It can be reproduced on my machine when observing a lot of files located in a non-trivial structure. At first it is all normal and pathwatcher observes file paths taking less than 1% of CPU. Later, when it reaches a specific point through the list of paths to observe, it gets node process to 100% CPU in less than a second.

After adding a lot of logging, I found out that the call to WaitForMultipleObjects returns -1 (which means an error occurred) and the error code is 87, which means ERROR_INVALID_PARAMETER.

Furthermore, investigating the size of g_events on every iteration of the loop seems to be 65, which is exactly one bigger than the maximum number of events the WaitForMultipleObjects call can wait on. I am not sure if it is related or not, because this happens even before node spikes to 100% CPU.

Windows 7 32-bit.

The code for a reproduction:

pathwatcher = require('pathwatcher')

files = [
"C:\\Users\\IEUser\\meteor\\dev_bundle\\.bundle_version.txt",
  "C:\\Users\\IEUser\\meteor\\packages\\underscore\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\underscore\\pre.js",
  "C:\\Users\\IEUser\\meteor\\packages\\underscore\\underscore.js",
  "C:\\Users\\IEUser\\meteor\\packages\\underscore\\post.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\server_environment.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\helpers.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\setimmediate.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\timers.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\errors.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\fiber_helpers.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\startup_server.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\debug.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\dynamics_nodejs.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\url_server.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\url_common.js",
  "C:\\Users\\IEUser\\meteor\\packages\\meteor\\plugin\\basic-file-types.js",
  "C:\\Users\\IEUser\\meteor\\packages\\json\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\base64\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\base64\\base64.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ejson\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ejson\\ejson.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ejson\\stringify.js",
  "C:\\Users\\IEUser\\meteor\\packages\\logging\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\logging\\.npm\\package\\npm-shrinkwrap.json",
  "C:\\Users\\IEUser\\meteor\\packages\\logging\\logging.js",
  "C:\\Users\\IEUser\\meteor\\packages\\routepolicy\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\routepolicy\\routepolicy.js",
  "C:\\Users\\IEUser\\meteor\\packages\\tracker\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\tracker\\tracker.js",
  "C:\\Users\\IEUser\\meteor\\packages\\tracker\\deprecated.js",
  "C:\\Users\\IEUser\\meteor\\packages\\deps\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\htmljs\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\htmljs\\preamble.js",
  "C:\\Users\\IEUser\\meteor\\packages\\htmljs\\visitors.js",
  "C:\\Users\\IEUser\\meteor\\packages\\htmljs\\html.js",
  "C:\\Users\\IEUser\\meteor\\packages\\html-tools\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\html-tools\\utils.js",
  "C:\\Users\\IEUser\\meteor\\packages\\html-tools\\scanner.js",
  "C:\\Users\\IEUser\\meteor\\packages\\html-tools\\charref.js",
  "C:\\Users\\IEUser\\meteor\\packages\\html-tools\\tokenize.js",
  "C:\\Users\\IEUser\\meteor\\packages\\html-tools\\templatetag.js",
  "C:\\Users\\IEUser\\meteor\\packages\\html-tools\\parse.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze-tools\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze-tools\\preamble.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze-tools\\tokens.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze-tools\\tojs.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minifiers\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minifiers\\.npm\\package\\npm-shrinkwrap.json",
  "C:\\Users\\IEUser\\meteor\\packages\\minifiers\\minification.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minifiers\\minifiers.js",
  "C:\\Users\\IEUser\\meteor\\packages\\spacebars-compiler\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\spacebars-compiler\\templatetag.js",
  "C:\\Users\\IEUser\\meteor\\packages\\spacebars-compiler\\optimizer.js",
  "C:\\Users\\IEUser\\meteor\\packages\\spacebars-compiler\\codegen.js",
  "C:\\Users\\IEUser\\meteor\\packages\\spacebars-compiler\\compiler.js",
  "C:\\Users\\IEUser\\meteor\\packages\\jquery\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\id-map\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\id-map\\id-map.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ordered-dict\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ordered-dict\\ordered_dict.js",
  "C:\\Users\\IEUser\\meteor\\packages\\random\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\random\\random.js",
  "C:\\Users\\IEUser\\meteor\\packages\\random\\deprecated.js",
  "C:\\Users\\IEUser\\meteor\\packages\\geojson-utils\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\geojson-utils\\pre.js",
  "C:\\Users\\IEUser\\meteor\\packages\\geojson-utils\\geojson-utils.js",
  "C:\\Users\\IEUser\\meteor\\packages\\geojson-utils\\post.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\minimongo.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\wrap_transform.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\helpers.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\selector.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\sort.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\projection.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\modify.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\diff.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\id_map.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\observe.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\objectid.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\selector_projection.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\selector_modifier.js",
  "C:\\Users\\IEUser\\meteor\\packages\\minimongo\\sorter_projection.js",
  "C:\\Users\\IEUser\\meteor\\packages\\observe-sequence\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\observe-sequence\\observe_sequence.js",
  "C:\\Users\\IEUser\\meteor\\packages\\reactive-var\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\reactive-var\\reactive-var.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\preamble.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\exceptions.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\view.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\builtins.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\lookup.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\template.js",
  "C:\\Users\\IEUser\\meteor\\packages\\blaze\\backcompat.js",
  "C:\\Users\\IEUser\\meteor\\packages\\templating\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\templating\\plugin\\html_scanner.js",
  "C:\\Users\\IEUser\\meteor\\packages\\templating\\plugin\\compile-templates.js",
  "C:\\Users\\IEUser\\meteor\\packages\\spacebars\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\spacebars\\spacebars-runtime.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ui\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\boilerplate-generator\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\boilerplate-generator\\boilerplate-generator.js",
  "C:\\Users\\IEUser\\meteor\\packages\\boilerplate-generator\\boilerplate_web.browser.html",
  "C:\\Users\\IEUser\\meteor\\packages\\boilerplate-generator\\boilerplate_web.cordova.html",
  "C:\\Users\\IEUser\\meteor\\packages\\webapp-hashing\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\webapp-hashing\\webapp-hashing.js",
  "C:\\Users\\IEUser\\meteor\\packages\\webapp\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\webapp\\.npm\\package\\npm-shrinkwrap.json",
  "C:\\Users\\IEUser\\meteor\\packages\\webapp\\webapp_server.js",
  "C:\\Users\\IEUser\\meteor\\packages\\check\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\check\\match.js",
  "C:\\Users\\IEUser\\meteor\\packages\\retry\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\retry\\retry.js",
  "C:\\Users\\IEUser\\meteor\\packages\\callback-hook\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\callback-hook\\hook.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\.npm\\package\\npm-shrinkwrap.json",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\common.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\stream_client_nodejs.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\stream_client_common.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\stream_server.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\heartbeat.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\livedata_server.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\writefence.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\crossbar.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\livedata_common.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\random_stream.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\livedata_connection.js",
  "C:\\Users\\IEUser\\meteor\\packages\\ddp\\server_convenience.js",
  "C:\\Users\\IEUser\\meteor\\packages\\session\\package.js",
  "C:\\Users\\IEUser\\asdf\\.meteor\\release",
  "C:\\Users\\IEUser\\asdf\\.meteor\\packages",
  "C:\\Users\\IEUser\\asdf\\.meteor\\versions",
  "C:\\Users\\IEUser\\asdf\\.meteor\\platforms",
  "C:\\Users\\IEUser\\asdf\\.meteor",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-base\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-facebook\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-github\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-google\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-meetup\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-meteor-developer\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-oauth-helper",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-oauth\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-oauth1-helper",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-oauth2-helper",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-password\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-twitter\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-ui-unstyled\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-ui\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\accounts-weibo\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\appcache\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\application-configuration\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\audit-argument-checks\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\autopublish\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\autoupdate\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\binary-heap\\package.js",
  "C:\\Users\\IEUser\\meteor\\packages\\browser-policy-common\\package.js" // this line causes issues!
  ]


for (var i in files) {
  var filepath = files[i];
  pathwatcher.watch(filepath, function () {

    console.log('changed');
  });
}

Open file windows don't get updated with new paths

If I have a file "scripts/app.js" and I decided to move it to a new location "app/app.js", if the file window was open while I do the transfer, the path of the opened file window will not get updated to the new location. This has caused me a lot of confusion when I edit the file through it's still-open window I finds out that the new updates have been persisted in the old file path instead of the new one.

Locks folders (cannot rename/delete) on Windows

I believe this module may cause the problems in:
atom/atom#3365

It appears that libuv has fixed this a while ago:
nodejs/node#375

I think this means that recursive fs.watch that does not lock any folder should now be available in node core.

Can this module be fixed? Alternatively, could it be replaced with something like chokidar instead?

What does this module do that others don't?

Fails to build with VS2012? (or 13?)

running npm install results in:

    gyp ERR! build error 
    gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onExit (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
    gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:807:12)
    gyp ERR! System Windows_NT 6.2.9200
    gyp ERR! command "node" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
    gyp ERR! cwd C:\Users\live_000\Documents\Code\node-pathwatcher
    gyp ERR! node -v v0.10.28
    gyp ERR! node-gyp -v v0.13.0
    gyp ERR! not ok 

    npm ERR! [email protected] install: `node-gyp rebuild`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the [email protected] install script.
    npm ERR! This is most likely a problem with the pathwatcher package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR!     node-gyp rebuild
    npm ERR! You can get their info via:
    npm ERR!     npm owner ls pathwatcher
    npm ERR! There is likely additional logging output above.
    npm ERR! System Windows_NT 6.2.9200
    npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
    npm ERR! cwd C:\Users\live_000\Documents\Code\node-pathwatcher
    npm ERR! node -v v0.10.28
    npm ERR! npm -v 1.4.9
    npm ERR! code ELIFECYCLE
    npm ERR! 
    npm ERR! Additional logging details can be found in:
    npm ERR!     C:\Users\live_000\Documents\Code\node-pathwatcher\npm-debug.log
    npm ERR! not ok code 0

First found in atom/atom#2023 but I'm confirming this isn't atom-specific.

Module version mismatch when building.

There's a module version mismatch when building the package.
Adding in a step 5.5. apm rebuild doesn't solve.

  1. git clone https://github.com/atom/node-pathwatcher.git
  2. cd node-pathwatcher
  3. apm link
  4. npm install
  5. npm test
  6. Open Atom

Atom Version: 1.5.3
System: Mac OS X 10.11.4
Thrown From: pathwatcher package, v6.4.0

Stack Trace

Failed to load the pathwatcher package

At Module version mismatch. Expected 46, got 47.

Error: Module version mismatch. Expected 46, got 47.
    at Error (native)
    at Object.module.(anonymous function) (ATOM_SHELL_ASAR.js:137:20)
    at Object.module.(anonymous function) [as .node] (ATOM_SHELL_ASAR.js:137:20)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (/Applications/Atom.app/Contents/Resources/app.asar/src/native-compile-cache.js:50:27)
    at Object.<anonymous> (/Users/andybayer/github/node-pathwatcher/lib/main.js:6:13)
    at Object.<anonymous> (/Users/andybayer/github/node-pathwatcher/lib/main.js:213:4)
    at Module.contents.overrideModuleCompile.Module._compile (/Applications/Atom.app/Contents/Resources/app.asar/src/native-compile-cache.js:103:30)
    at Object.keys.forEach.Object.defineProperty.value [as .js] (/Applications/Atom.app/Contents/Resources/app.asar/src/compile-cache.js:208:21)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (/Applications/Atom.app/Contents/Resources/app.asar/src/native-compile-cache.js:50:27)
    at Package.module.exports.Package.requireMainModule (/Applications/Atom.app/Contents/Resources/app.asar/src/package.js:720:27)
    at /Applications/Atom.app/Contents/Resources/app.asar/src/package.js:116:28
    at Package.module.exports.Package.measure (/Applications/Atom.app/Contents/Resources/app.asar/src/package.js:92:15)
    at Package.module.exports.Package.load (/Applications/Atom.app/Contents/Resources/app.asar/src/package.js:106:12)
    at PackageManager.module.exports.PackageManager.loadPackage (/Applications/Atom.app/Contents/Resources/app.asar/src/package-manager.js:445:14)
    at PackageManager.module.exports.PackageManager.loadPackages (/Applications/Atom.app/Contents/Resources/app.asar/src/package-manager.js:395:14)
    at AtomEnvironment.module.exports.AtomEnvironment.startEditorWindow (/Applications/Atom.app/Contents/Resources/app.asar/src/atom-environment.js:684:21)
    at module.exports (/Applications/Atom.app/Contents/Resources/app.asar/src/initialize-application-window.js:28:10)
    at setupWindow (file:///Applications/Atom.app/Contents/Resources/app.asar/static/index.js:86:5)
    at window.onload (file:///Applications/Atom.app/Contents/Resources/app.asar/static/index.js:41:9)

Commands

Config

{
  "core": {
    "disabledPackages": [
      "linter-eslint",
      "markdown-preview",
      "autocomplete-plus"
    ]
  }
}

Installed Packages

# User
editorconfig, v1.2.4
language-pfm, v0.82.0
linter, v1.11.3
markdown-preview-plus, v2.2.2
pathwatcher, v6.4.0
preview-inline, v0.5.1
text-buffer, v8.3.0

# Dev
git-tabs, v0.3.0

node-pathwatcher error undefined symbol _Z12PlatformInitv

Trying to compile and run node-pathwatcher on FreeBSD. Compiling runs fine without any issue but when using that package

require 'pathwatcher'

error ist thrown

node_modules/pathwatcher/build/Release/pathwatcher.node: Undefined symbol "_Z12PlatformInitv"

Thanks for help

Update Readme with some API?

I can update it with some methods like closeAllWatchers and getWatchedPaths and etc if you want. (or they supposed to be used for testing?)

use fsevents for os x

kevent really sucks

fsevents can watch whole dir trees instantly and gives a lot more info about changes

Corrupts (Most) Binary Files

Atom corrupts binary files in many (most?) cases. To test:

  1. make a binary file (eg a tarball)
  2. md5 tarball
  3. open file in atom
  4. save file (you can make a change and undo if you want)
  5. md5 tarball

Pathwatcher just assumes everything is utf8 (before reading the files).
example: https://github.com/atom/node-pathwatcher/blob/master/src/file.coffee#L215

I don't really want to edit binary files in atom (its too damn slow for one thing), but accidentally opening a binary file and saving it is a thing that happens.

`npm install` in node-pathwatcher raises errors with Node 4.0.0

 20:33:10 ๎‚ฐ dan@elise:~/stuff/node-pathwatcher ๎‚ฐ ๎‚  master โœ” ๎‚ฐ
$ npm install
npm WARN package.json [email protected] No license field.

> [email protected] install /Users/dan/stuff/node-pathwatcher/node_modules/runas
> node-gyp rebuild

  CXX(target) Release/obj.target/runas/src/main.o
In file included from ../src/main.cc:1:
../node_modules/nan/nan.h:260:25: error: redefinition of '_NanEnsureLocal'
NAN_INLINE v8::Local<T> _NanEnsureLocal(v8::Local<T> val) {
                        ^
../node_modules/nan/nan.h:255:25: note: previous definition is here
NAN_INLINE v8::Local<T> _NanEnsureLocal(v8::Handle<T> val) {
                        ^
../node_modules/nan/nan.h:660:13: error: no member named 'smalloc' in namespace 'node'
    , node::smalloc::FreeCallback callback
      ~~~~~~^
../node_modules/nan/nan.h:671:12: error: no matching function for call to 'New'
    return node::Buffer::New(v8::Isolate::GetCurrent(), data, size);
           ^~~~~~~~~~~~~~~~~
/Users/dan/.node-gyp/4.0.0/src/node_buffer.h:31:40: note: candidate function not viable: no known conversion from
      'uint32_t' (aka 'unsigned int') to 'enum encoding' for 3rd argument
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                       ^
/Users/dan/.node-gyp/4.0.0/src/node_buffer.h:43:40: note: candidate function not viable: 2nd argument ('const char *')
      would lose const qualifier
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                       ^
/Users/dan/.node-gyp/4.0.0/src/node_buffer.h:28:40: note: candidate function not viable: requires 2 arguments, but 3
      were provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
                                       ^
/Users/dan/.node-gyp/4.0.0/src/node_buffer.h:36:40: note: candidate function not viable: requires 5 arguments, but 3
      were provided
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
                                       ^
In file included from ../src/main.cc:1:
../node_modules/nan/nan.h:675:12: error: no viable conversion from 'v8::MaybeLocal<v8::Object>' to
      'v8::Local<v8::Object>'
    return node::Buffer::New(v8::Isolate::GetCurrent(), size);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:210:7: note: candidate constructor (the implicit copy constructor) not
      viable: no known conversion from 'v8::MaybeLocal<v8::Object>' to 'const v8::Local<v8::Object> &' for 1st
      argument
class Local {
      ^
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:210:7: note: candidate constructor (the implicit move constructor) not
      viable: no known conversion from 'v8::MaybeLocal<v8::Object>' to 'v8::Local<v8::Object> &&' for 1st argument
class Local {
      ^
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:214:13: note: candidate template ignored: could not match 'Local'
      against 'MaybeLocal'
  V8_INLINE Local(Local<S> that)
            ^
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:326:13: note: candidate template ignored: could not match 'S *'
      against 'v8::MaybeLocal<v8::Object>'
  V8_INLINE Local(S* that)
            ^
In file included from ../src/main.cc:1:
../node_modules/nan/nan.h:682:26: error: no member named 'Use' in namespace 'node::Buffer'
    return node::Buffer::Use(v8::Isolate::GetCurrent(), data, size);
           ~~~~~~~~~~~~~~^
In file included from ../src/main.cc:1:
In file included from ../node_modules/nan/nan.h:24:
In file included from /Users/dan/.node-gyp/4.0.0/src/node.h:42:
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:221:5: error: assigning to 'v8::Primitive *volatile' from incompatible
      type 'v8::Value *'
    TYPE_CHECK(T, S);
    ^~~~~~~~~~~~~~~~
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:180:37: note: expanded from macro 'TYPE_CHECK'
    *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
                                    ^ ~~~~~~~~~~~~~~~~~~
../node_modules/nan/nan.h:413:12: note: in instantiation of function template specialization
      'v8::Local<v8::Primitive>::Local<v8::Value>' requested here
    return NanEscapeScope(NanNew(v8::Undefined(v8::Isolate::GetCurrent())));
           ^
../node_modules/nan/nan.h:397:30: note: expanded from macro 'NanEscapeScope'
# define NanEscapeScope(val) scope.Escape(_NanEnsureLocal(val))
                             ^
In file included from ../src/main.cc:1:
In file included from ../node_modules/nan/nan.h:24:
In file included from /Users/dan/.node-gyp/4.0.0/src/node.h:42:
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:221:5: error: assigning to 'v8::Boolean *volatile' from incompatible
      type 'v8::Value *'
    TYPE_CHECK(T, S);
    ^~~~~~~~~~~~~~~~
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:180:37: note: expanded from macro 'TYPE_CHECK'
    *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
                                    ^ ~~~~~~~~~~~~~~~~~~
../node_modules/nan/nan.h:423:12: note: in instantiation of function template specialization
      'v8::Local<v8::Boolean>::Local<v8::Value>' requested here
    return NanEscapeScope(NanNew(v8::True(v8::Isolate::GetCurrent())));
           ^
../node_modules/nan/nan.h:397:30: note: expanded from macro 'NanEscapeScope'
# define NanEscapeScope(val) scope.Escape(_NanEnsureLocal(val))
                             ^
In file included from ../src/main.cc:1:
In file included from ../node_modules/nan/nan.h:24:
In file included from /Users/dan/.node-gyp/4.0.0/src/node.h:42:
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:221:5: error: assigning to 'v8::Function *volatile' from incompatible
      type 'v8::Value *'
    TYPE_CHECK(T, S);
    ^~~~~~~~~~~~~~~~
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:180:37: note: expanded from macro 'TYPE_CHECK'
    *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
                                    ^ ~~~~~~~~~~~~~~~~~~
../node_modules/nan/nan.h:1513:12: note: in instantiation of function template specialization
      'v8::Local<v8::Function>::Local<v8::Value>' requested here
    return NanEscapeScope(NanNew(handle)->Get(kCallbackIndex)
           ^
../node_modules/nan/nan.h:397:30: note: expanded from macro 'NanEscapeScope'
# define NanEscapeScope(val) scope.Escape(_NanEnsureLocal(val))
                             ^
In file included from ../src/main.cc:1:
In file included from ../node_modules/nan/nan.h:24:
In file included from /Users/dan/.node-gyp/4.0.0/src/node.h:42:
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:221:5: error: assigning to 'v8::Object *volatile' from incompatible
      type 'v8::Value *'
    TYPE_CHECK(T, S);
    ^~~~~~~~~~~~~~~~
/Users/dan/.node-gyp/4.0.0/deps/v8/include/v8.h:180:37: note: expanded from macro 'TYPE_CHECK'
    *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
                                    ^ ~~~~~~~~~~~~~~~~~~
../node_modules/nan/nan.h:1631:12: note: in instantiation of function template specialization
      'v8::Local<v8::Object>::Local<v8::Value>' requested here
    return NanEscapeScope(handle->Get(NanNew(key)).As<v8::Object>());
           ^
../node_modules/nan/nan.h:397:30: note: expanded from macro 'NanEscapeScope'
# define NanEscapeScope(val) scope.Escape(_NanEnsureLocal(val))
                             ^
9 errors generated.
make: *** [Release/obj.target/runas/src/main.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
ERR! System Darwin 14.5.0
gyp ERR! command "/usr/local/bin/iojs" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/dan/stuff/node-pathwatcher/node_modules/runas
gyp ERR! node -v v4.0.0
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok
npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "install"
npm ERR! node v4.0.0
npm ERR! npm  v2.14.3
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the runas package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls runas
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/dan/stuff/node-pathwatcher/npm-debug.log

dlopen error on OS X Mavericks and node 0.10

I'm trying to include PathWatcher in my project, but I get this error on start.

"Uncaught Error: dlopen(/Users/timosand/Development/reposive-syncer/node_modules/pathwatcher/build/Release/pathwatcher.node, 1): no suitable image found.  Did find:
    /Users/timosand/Development/reposive-syncer/node_modules/pathwatcher/build/Release/pathwatcher.node: mach-o, but wrong architecture", source: /Users/timosand/Development/reposive-syncer/node_modules/pathwatcher/node_modules/bindings/bindings.js (83)

Cache created File and Directory objects.

It seems wasteful to create duplicate File and Directory objects for the same path. For example, every time Directory.getSubdirectory() is invoked, it returns a new Directory.

The constructors of File and Directory should be private. Getting access to an instance of either should go through a creation method that has the ability to consult a cache.

Failed to build using vs2010

Because of WarnAsError is set to true, there is new error occured during compilation:

..\src\common.cc(58): error C2220: warning treated as error - no 'object' file generated [F:\atom-shell\spec\node_modules\pathwatcher\build\pathwatcher.vcxproj]
..\src\common.cc(58): warning C4344: behavior change: use of explicit template arguments results in call to 'v8::Local<T> NanNew<v8::String,char*>(char *,int)'[F:\atom-shell\spec\node_modules\pathwatcher\build\pathwatcher.vcxproj]
          with
          [
              T=v8::String
          ]
          but the regular function 'v8::Local<T> NanNew(const char *,int)' is a better match
          with
          [
              T=v8::String
          ]
          if you expect 'v8::Local<T> NanNew(const char *,int)' to be called then you need to make it an explicit specialization
          with
          [
              T=v8::String
          ]
..\src\common.cc(59): warning C4344: behavior change: use of explicit template arguments results in call to 'v8::Local<T> NanNew<v8::String,char*>(char *,int)'[F:\atom-shell\spec\node_modules\pathwatcher\build\pathwatcher.vcxproj]
          with
          [
              T=v8::String
          ]
          but the regular function 'v8::Local<T> NanNew(const char *,int)' is a better match
          with
          [
              T=v8::String
          ]
          if you expect 'v8::Local<T> NanNew(const char *,int)' to be called then you need to make it an explicit specialization
          with
          [
              T=v8::String
          ]

Just wonder if it is necessary to set WarnAsError?

Unable to use this module in Electron's renderer process

Hi,
I am using electron v0.25.1 and pathwatcher v4.4.0. When I require pathwatcher in my app's renderer process, I get the following error:

var Pathwatcher = require('pathwatcher');
Uncaught Error: Module did not self-register.message: "Module did not self-register."stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: 

Any help would be much appreciated.

Thanks

Is there a reason to limit events to 'rename', 'delete' and 'change'?

I ask because of a problem, I described here.
Before I can consider making a PR, I have to know if there is a specific reason why the create event gets relabeled into a change event?

Will it break something if I change it?

Use case: I can't watch individual compiled files, as they get deleted before recompilation but watching the directory isn't specific enough.

[Windows] Unable to watch path

After using the Atom editor for a while, it will refuse to open files and pop open the debugging console with an error: Uncaught TypeError: Unable to watch path

image

The editor usually works fine, but then will stop opening files once this starts.

I noticed a similar issue on Linux, but this is happening on Windows.

If the file watching fails, I'd expect a subtle warning (or no warning at all) and for the file I tried to open to open - not for it to refuse to open the file.

Potentially relevant information - this is on Windows 8.1 update 1, and the directory that is open is on a network drive. Also, it generally works (often for days) - but then stops working, so it must be able to watch these files sometimes.

Build failure on Windows

C:\atom\atom\node_modules\pathwatcher>node "C:\atom\atom\vendor\apm\node_modules\npm\bin\node-gyp-bin\\..\..\node_module
s\node-gyp\bin\node-gyp.js" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  main.cc
  common.cc
c:\users\paul\.atom\.node-gyp\.node-gyp\0.10.18\deps\uv\include\uv-private/uv-win.h(32): fatal error C1083: Cannot open
include file: 'winsock2.h': No such file or directory (..\src\main.cc) [C:\atom\atom\node_modules\pathwatcher\build\path
watcher.vcxproj]
c:\users\paul\.atom\.node-gyp\.node-gyp\0.10.18\deps\uv\include\uv-private/uv-win.h(32): fatal error C1083: Cannot open
include file: 'winsock2.h': No such file or directory (..\src\common.cc) [C:\atom\atom\node_modules\pathwatcher\build\pa
thwatcher.vcxproj]

Crash

Crash reason:  EXC_BAD_ACCESS / 0x0000000d
Crash address: 0x0

Thread 0 (crashed)
 0  pathwatcher.node!__ZN9HandleMap6ValuesERKN2v820FunctionCallbackInfoINS0_5ValueEEE + 0x7b
    rbx = 0x0000000000000003   r12 = 0x00007fa3296236a0
    r13 = 0x00007fa3296e0a7f   r14 = 0x00007fff5d16b9b8
    r15 = 0x00007fa32d84ac88   rip = 0x000000010b3e3dbb
    rsp = 0x00007fff5d16b950   rbp = 0x00007fff5d16b9a0
    Found by: given as instruction pointer in context
 1  pathwatcher.node!__ZN9HandleMap3HasERKN2v820FunctionCallbackInfoINS0_5ValueEEE + 0x16e
    rip = 0x000000010b3e3d40   rsp = 0x00007fff5d16b998
    rbp = 0x00007fff5d16b9a0
    Found by: stack scanning
 2  libchromiumcontent.dylib!v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [arguments.cc : 56 + 0x3]
    rip = 0x000000010428051e   rsp = 0x00007fff5d16b9b0
    rbp = 0x00007fff5d16ba10
    Found by: stack scanning
 3  pathwatcher.node!__ZN9HandleMap3HasERKN2v820FunctionCallbackInfoINS0_5ValueEEE + 0x16e
    rip = 0x000000010b3e3d40   rsp = 0x00007fff5d16b9e0
    rbp = 0x00007fff5d16ba10
    Found by: stack scanning
 4  libchromiumcontent.dylib!v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [builtins.cc : 1272 + 0xc]
    rip = 0x000000010429b1e9   rsp = 0x00007fff5d16ba20
    rbp = 0x00007fff5d16bac0
    Found by: stack scanning
 5  pathwatcher.node!__ZN9HandleMap3HasERKN2v820FunctionCallbackInfoINS0_5ValueEEE + 0x16e
    rip = 0x000000010b3e3d40   rsp = 0x00007fff5d16ba28
    rbp = 0x00007fff5d16bac0
    Found by: stack scanning
 6  libchromiumcontent.dylib + 0x1163060
    rip = 0x000000010429b060   rsp = 0x00007fff5d16baa0
    rbp = 0x00007fff5d16bac0
    Found by: stack scanning

Error: A dynamic link library DLL initialization routine failed.

I am trying to get pathwatcher working with one of the electron example apps on the electron-sample-apps repo.

package.json
{ "name": "pathwather-test", "version": "0.0.0", "description": "", "main": "main.js", "scripts": { "start": "electron .", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "devDependencies": { "electron-prebuilt-compile": "^1.2.2" }, "dependencies": { "pathwatcher": "^6.7.0" } }

When adding the line require('pathwatcher') to any of my sources file it get the following error.

  • Windows 10 x64
  • npm version 3.9.5
  • node version 4.4.5

Subscription.close is not synchronous

My gut says that it should be, but if we want to maintain it as async, then I think we should have closeSync.

It would make things substantially easier on Windows where you must unwatch things before removing files.

6.3.0 fails to build on windows

6.2.5 is building successfully.

..\src\common.cc(150): error C2664: 'void Nan::ReturnValue<T>::Set(uint32_t)': cannot convert argument 1 from 'v8::Handle<v8::Value>' to 'bool' [C:\Projects\temp\node_modules\pathwatcher\build\pathwatcher.vcxproj]

with
[
    T=v8::Value
]
..\src\common.cc(150): note: no user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Fortunately i've got my packages shrinkwrapped, but unfortunately shrinkwrap is working for every package EXCEPT pathwatcher (shrinkwrapped to 6.2.5 but it installs 6.3.0, no clue why), so this is kind of blocking things up for a number of our developers :/.

onDidChangePath not called for fs.renameSync on Linux

Simple repro steps:

# init.coffee
atom.workspace.observeActivePaneItems (item) ->
  item.onDidChangePath ->
    console.log 'PATH CHANGED'
// Dev tools
var fs = require('fs-plus');
var bufferToChange = atom.workspace.getActivePaneItem();
var filePath = bufferToChange.getPath();
var newPath = filePath + "2";
fs.moveSync(filePath, newPath);  //or .removeSync()

Observe that 'PATH CHANGED' does not appear in the console. If you change moveSync to .saveAs(), 'PATH CHANGED' will appear.

To verify that a fix works just make sure this text-buffer spec passes on Linux.

Refs atom/atom#7315.

[Linux] Feedback

Works incredibly fast.

When file gets deleted and recreated again very quickly(for example when compiler generates JavaScript file), watcher emits change and delete and stops watching file, so I had to manually wait 1500 ms, before checking if file exists, and if it exists - then start watching again Pathwatcher.watch, and check if file modified since last time to detect if file tab needs reloading.(in my IDE based on atom-shell).

Without delay of 1500 ms, it doesn't seems to start watching again.

Great job guys! Very fast!

Unable to watch more than 64 directories on Windows

I am using pathwatcher in my own component and love it. I was using it the other day in a bigger project and all of the sudden I wasn't getting any notifications anymore.

After debugging pathwatcher it turns out to be a limitation in the Windows API that pathwatcher uses:

    DWORD r = WaitForMultipleObjects(copied_events.size(),
                                     copied_events.data(),
                                     FALSE,
                                     INFINITE);

in function PlatformThread() in pathwatcher_win.cc

Luckily there is a workaround to this problem given in the documentation on MSDN
https://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx

To wait on more than MAXIMUM_WAIT_OBJECTS handles, use one of the following methods:

  1. Create a thread to wait on MAXIMUM_WAIT_OBJECTS handles, then wait on that thread plus the other handles. Use this technique to break the handles into groups of MAXIMUM_WAIT_OBJECTS.
  2. Call RegisterWaitForSingleObject to wait on each handle. A wait thread from the thread pool waits on MAXIMUM_WAIT_OBJECTS registered objects and assigns a worker thread after the object is signaled or the time-out interval expires.

Can this be fixed please ?

Btw, with your 65th directory the PlatformThread() function ends up in a continuous loop that uses 100% CPU as the function doesn't wait anymore but returns immediately. At a minimum the code should check the size and not pass in more than 64 objects.

Merely calling require("pathwatcher") keeps the process from exiting

Minimal repro: node -e 'require("pathwatcher")'

The default behavior seems to be similar to calling fs.watch(file, { persistent: true }), which keeps the event loop alive until all watchers are closed. I would love to have the ability to make pathwatcher.watch non-persistent.

From brief examination, it seems like we need to be calling uv_run(loop, UV_RUN_NOWAIT) somewhere, perhaps instead of uv_async_init(uv_default_loop(), &g_async, MakeCallbackInMainThread), but I'm far from certain about that.

For what it's worth, I'm a Meteor core developer, and I'm trying to incorporate pathwatcher into the Meteor development server, to address meteor/meteor#2135.

TypeError: Unable to watch path

I was able to use Atom on my Ubuntu 14.04 machine. But now I am facing this issue which does not allow me to use the editor at all.

atom_pathwatcher_bug

Issue during atom build with pathwatcher

Hi,

trying to build latest master of atom fails with an issue with pathwatcher.

I do not understand it. But maybe you do? :)

If you need more info let me know what you need:

ablu@localhost: ~/atom (master)$ script/build
Node: v0.10.29
npm: v1.4.13
Installing build modules...
Installing apm...
Installing modules โœ—
> [email protected] preinstall /home/ablu/atom
> node -e 'process.exit(0)'


> [email protected] install /home/ablu/atom/node_modules/pathwatcher
> node-gyp rebuild


> [email protected] install /home/ablu/atom/node_modules/git-utils
> node-gyp rebuild


Traceback (most recent call last):
  File "/home/ablu/atom/apm/node_modules/atom-package-manager/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 18, in <module>
    sys.exit(gyp.script_main())
AttributeError: 'module' object has no attribute 'script_main'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/home/ablu/atom/apm/node_modules/atom-package-manager/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.15.4-200.fc20.x86_64
gyp ERR! command "node" "/home/ablu/atom/apm/node_modules/atom-package-manager/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ablu/atom/node_modules/pathwatcher
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the pathwatcher package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls pathwatcher
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.15.4-200.fc20.x86_64
npm ERR! command "/home/ablu/atom/apm/node_modules/atom-package-manager/bin/node" "/home/ablu/atom/apm/node_modules/atom-package-manager/node_modules/npm/bin/npm-cli.js" "--globalconfig" "/home/ablu/atom/apm/node_modules/atom-package-manager/.apmrc" "--userconfig" "/home/ablu/.atom/.apmrc" "install" "--target=0.11.10" "--arch=x64" "--quiet"
npm ERR! cwd /home/ablu/atom
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.4
npm ERR! code ELIFECYCLE
Traceback (most recent call last):
  File "/home/ablu/atom/apm/node_modules/atom-package-manager/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 18, in <module>
    sys.exit(gyp.script_main())
AttributeError: 'module' object has no attribute 'script_main'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/home/ablu/atom/apm/node_modules/atom-package-manager/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.15.4-200.fc20.x86_64
gyp ERR! command "node" "/home/ablu/atom/apm/node_modules/atom-package-manager/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ablu/atom/node_modules/git-utils
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/ablu/atom/npm-debug.log
npm ERR! not ok code 0

Regards,
Ablu

No path is returned on linux

inotify doesn't return the path on linux for file events, only the watch descriptor (e->wd), you have to remember which watch descriptor belongs to which path.
For directory events, you get the filename, so you have to find the directory path using the watch descriptor, and add the filename.

PathWatcher.watch spams stderr for nonexistent files

There's no way to call PathWatcher.watch("filename") so that it doesn't print to stderr if the file doesn't exist (fprintf on Mac, perror on Linux). Even if you check to see if the file exists first, there's room for a race condition. So if you want to use PathWatcher in a console program (as opposed to the invisible background process of some other UI), there's no way to avoid stderr potentially getting spammed with an error message.

(Also, it Would Be Nice (TM) if you could pass a nonexistent file to PathWatcher.watch and PathWatcher did the appropriate wrapper directory watches to notify you when it's created, but that's a separate issue.)

I'd be happy to submit a PR to remove the stderr prints, but I suspect that Atom may actually appreciate having them available somehow, and I'm not an expert on the proper way to manage memory around strings in Node/V8 C++. I guess you would want to get the error message into the NanThrowTypeError call?

node-pathwatcher doesn't build on Windows 7

On Windows 7 x64, node-pathwatcher does not build for me; I should have all the right tools. I get the following output:

$ npm install
npm WARN package.json [email protected] No repository field.
/
> [email protected] install c:\dev\git\node-pathwatcher
> node-gyp rebuild


c:\dev\git\node-pathwatcher>node "c:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\.
.\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m"
switch.
  main.cc
  common.cc
  handle_map.cc
  pathwatcher_win.cc
..\src\common.cc(57): error C2220: warning treated as error - no 'object' file generated [c:\dev\gi
t\node-pathwatcher\build\pathwatcher.vcxproj]
..\src\common.cc(57): warning C4344: behavior change: use of explicit template arguments results in
 call to 'v8::Local<T> NanNew<v8::String,char*>(P,int)' [c:\dev\git\node-pathwatcher\build\pathwatc
her.vcxproj]
          with
          [
              T=v8::String,
              P=char *
          ]
          but the regular function 'v8::Local<T> NanNew(const char *,int)' is a better match
          with
          [
              T=v8::String
          ]
          if you expect 'v8::Local<T> NanNew(const char *,int)' to be called then you need to make
  it an explicit specialization
          with
          [
              T=v8::String
          ]
..\src\common.cc(58): warning C4344: behavior change: use of explicit template arguments results in
 call to 'v8::Local<T> NanNew<v8::String,char*>(P,int)' [c:\dev\git\node-pathwatcher\build\pathwatc
her.vcxproj]
          with
          [
              T=v8::String,
              P=char *
          ]
          but the regular function 'v8::Local<T> NanNew(const char *,int)' is a better match
          with
          [
              T=v8::String
          ]
          if you expect 'v8::Local<T> NanNew(const char *,int)' to be called then you need to make
  it an explicit specialization
          with
          [
              T=v8::String
          ]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit c
ode: 1
gyp ERR! stack     at ChildProcess.onExit (c:\Program Files (x86)\nodejs\node_modules\npm\node_modul
es\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:810:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "c:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\
\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd c:\dev\git\node-pathwatcher
gyp ERR! node -v v0.10.31
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the pathwatcher package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls pathwatcher
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "c:\\Program Files (x86)\\nodejs\\node.exe" "c:\\Program Files (x86)\\nodejs\\node_
modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd c:\dev\git\node-pathwatcher
npm ERR! node -v v0.10.31
npm ERR! npm -v 1.4.23
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     c:\dev\git\node-pathwatcher\npm-debug.log
npm ERR! not ok code 0

Can't require on 2.3.2

{File} = require 'pathwatcher'

My Atom package fails completely on this and claims that the module fails to self register. Jumped back to 2.0.1 and it works.

It is better if user can catch a new file/dir event instead of 'change'

I read the source code of pathwatcher and found it can catch 'child-create' event. But after that pathwatcher will wrapper it into 'change' event without more information.

I wish I can add a file/dir watcher if a new file/dir created in my watched directory. But under current event and parameters, I can only setup a watch on the parent directory, and listen to the 'change' event, then compare the whole files in the directory to get the new coming file.

Is this possible, or am I doing it wrong ?

TypeError: Path must be a string

Hi all,
Trying to watch 1 file on Mac OS X + io.js 2.4.0 like this:

const watcher = PathWatcher.watch('./dist/bundle.js');

and get following stack trance

fs.js:549
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
TypeError: path must be a string
    at TypeError (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at PathWatcher.watch (/Users/xamd/Projects/browserify-react-live/server/index.js:46:25)
    at emitTwo (events.js:87:13)
    at PathWatcher.emit (events.js:172:7)
    at HandleWatcher.<anonymous> (/Users/xamd/Projects/browserify-react-live/node_modules/pathwatcher/lib/main.js:134:28)
    at emitThree (events.js:97:13)
    at HandleWatcher.emit (events.js:175:7)
    at HandleWatcher.onEvent (/Users/xamd/Projects/browserify-react-live/node_modules/pathwatcher/lib/main.js:60:23)

suggestions?

P.S. I've tried a lot of different combinations of path to watch, nothing works

directory method contains win32 error

directory.coffee in method contains line:

fullPath = fullPath.replace(///g, '') if process.platform is 'win32'

should be:

pathToCheck = pathToCheck.replace(///g, '') if process.platform is 'win32'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.