Fix PathWatcher failures

Now when a file is removed, we always remove its subscriptions and its kevent.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-11-19 13:15:35 -07:00
parent 5da44b9eef
commit f9563f5e55
5 changed files with 42 additions and 39 deletions

View File

@@ -31,23 +31,9 @@ class File
afterUnsubscribe: ->
@unsubscribeFromNativeChangeEvents() if @subscriptionCount() == 0
subscribeToNativeChangeEvents: ->
@watchId = $native.watchPath @path, (eventType, path) =>
@handleNativeChangeEvent(eventType, path)
handleNativeChangeEvent: (eventType, path) ->
console.log eventType
if eventType is "remove"
@unsubscribeFromNativeChangeEvents()
detectResurrection = =>
if @exists()
@subscribeToNativeChangeEvents()
@handleNativeChangeEvent("contents-change", path)
else
@trigger "remove"
@off()
_.delay detectResurrection, 50
@detectResurrectionAfterDelay()
else if eventType is "move"
@setPath(path)
@trigger "move"
@@ -58,6 +44,21 @@ class File
@md5 = newMd5
@trigger 'contents-change'
detectResurrectionAfterDelay: ->
_.delay (=> @detectResurrection()), 50
detectResurrection: ->
if @exists()
@subscribeToNativeChangeEvents()
@handleNativeChangeEvent("contents-change", @getPath())
else
@trigger "remove"
@off()
subscribeToNativeChangeEvents: ->
@watchId = $native.watchPath @path, (eventType, path) =>
@handleNativeChangeEvent(eventType, path)
unsubscribeFromNativeChangeEvents: ->
$native.unwatchPath(@path, @watchId)