Make paths absolute before calling $native.watchPath

Also return a subscription that can be unwatched instead
of returning an id that is later passed to $native.unwatchPath
along with the watched path.

This allows specs to pass when run from a symlink'ed folder.
This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-03-20 13:27:49 -07:00
parent ae96a48572
commit 6c357aaca7
5 changed files with 17 additions and 18 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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)