diff --git a/native/path_watcher.mm b/native/path_watcher.mm index e5cc65afe..47c7dee2f 100644 --- a/native/path_watcher.mm +++ b/native/path_watcher.mm @@ -99,7 +99,6 @@ static NSMutableArray *gPathWatchers; } - (NSString *)watchPath:(NSString *)path callback:(WatchCallback)callback callbackId:(NSString *)callbackId { - path = [path stringByStandardizingPath]; @synchronized(self) { if (![self createKeventForPath:path]) { NSLog(@"WARNING: Failed to create kevent for path '%@'", path); @@ -119,8 +118,6 @@ static NSMutableArray *gPathWatchers; } - (void)unwatchPath:(NSString *)path callbackId:(NSString *)callbackId error:(NSError **)error { - path = [path stringByStandardizingPath]; - @synchronized(self) { NSMutableDictionary *callbacks = [_callbacksByPath objectForKey:path]; @@ -154,8 +151,6 @@ static NSMutableArray *gPathWatchers; } - (bool)createKeventForPath:(NSString *)path { - path = [path stringByStandardizingPath]; - @synchronized(self) { if ([_fileDescriptorsByPath objectForKey:path]) { NSLog(@"we already have a kevent"); @@ -182,8 +177,6 @@ static NSMutableArray *gPathWatchers; } - (void)removeKeventForPath:(NSString *)path { - path = [path stringByStandardizingPath]; - @synchronized(self) { NSNumber *fdNumber = [_fileDescriptorsByPath objectForKey:path]; if (!fdNumber) { @@ -245,7 +238,7 @@ static NSMutableArray *gPathWatchers; char pathBuffer[MAXPATHLEN]; fcntl((int)event.ident, F_GETPATH, &pathBuffer); close(event.ident); - newPath = [[NSString stringWithUTF8String:pathBuffer] stringByStandardizingPath]; + newPath = [NSString stringWithUTF8String:pathBuffer]; if (!newPath) { NSLog(@"WARNING: Ignoring rename event for deleted file '%@'", path); continue; diff --git a/src/app/directory.coffee b/src/app/directory.coffee index 211ec42aa..74be74a44 100644 --- a/src/app/directory.coffee +++ b/src/app/directory.coffee @@ -34,10 +34,12 @@ class Directory @unsubscribeFromNativeChangeEvents() if @subscriptionCount() == 0 subscribeToNativeChangeEvents: -> - @watchId = $native.watchPath @path, (eventType) => + @watchSubscription = fs.watchPath @path, (eventType) => @trigger "contents-changed" if eventType is "contents-change" unsubscribeFromNativeChangeEvents: -> - $native.unwatchPath(@path, @watchId) + if @watchSubscription? + @watchSubscription.unwatch() + @watchSubscription = null _.extend Directory.prototype, EventEmitter diff --git a/src/app/file.coffee b/src/app/file.coffee index 8ecc33e68..ad02a4943 100644 --- a/src/app/file.coffee +++ b/src/app/file.coffee @@ -10,7 +10,7 @@ class File constructor: (@path) -> if @exists() and not fs.isFile(@path) - throw new Error(@path + " is a directory") + throw new Error("#{@path} is a directory") setPath: (@path) -> @@ -67,10 +67,12 @@ class File @trigger "removed" subscribeToNativeChangeEvents: -> - @watchId = $native.watchPath @path, (eventType, path) => + @watchSubscription = fs.watchPath @path, (eventType, path) => @handleNativeChangeEvent(eventType, path) unsubscribeFromNativeChangeEvents: -> - $native.unwatchPath(@path, @watchId) + if @watchSubscription + @watchSubscription.unwatch() + @watchSubscription = null _.extend File.prototype, EventEmitter diff --git a/src/packages/tree-view/spec/tree-view-spec.coffee b/src/packages/tree-view/spec/tree-view-spec.coffee index a4e7bc604..dc7645ed2 100644 --- a/src/packages/tree-view/spec/tree-view-spec.coffee +++ b/src/packages/tree-view/spec/tree-view-spec.coffee @@ -601,7 +601,7 @@ describe "TreeView", -> beforeEach -> rootView.deactivate() - rootDirPath = "/tmp/atom-tests" + rootDirPath = fs.join(fs.absolute("/tmp"), "atom-tests") fs.remove(rootDirPath) if fs.exists(rootDirPath) dirPath = fs.join(rootDirPath, "test-dir") diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index f1ae8678f..bda26c9bf 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -19,10 +19,7 @@ module.exports = home = process.env.HOME path = "#{home}#{path.substring(1)}" try - path = fs.realpathSync(path) - if process.platform is 'darwin' and path.indexOf('/private/') is 0 - path = path.substring(8) - path + fs.realpathSync(path) catch e path @@ -285,3 +282,8 @@ module.exports = cson.readObject(path) else @readPlist(path) + + watchPath: (path, callback) -> + path = @absolute(path) + id = $native.watchPath(path, callback) + unwatch: -> $native.unwatchPath(path, id)