diff --git a/src/app/file.coffee b/src/app/file.coffee index 72138ebb2..f982223b5 100644 --- a/src/app/file.coffee +++ b/src/app/file.coffee @@ -1,6 +1,7 @@ EventEmitter = require 'event-emitter' -fs = require 'fs-utils' +fs = require 'fs' +fsUtils = require 'fs-utils' _ = require 'underscore' module.exports = @@ -9,32 +10,33 @@ class File cachedContents: null constructor: (@path, @symlink=false) -> - if @exists() and not fs.isFile(@path) - throw new Error("#{@path} is a directory") + try + if fs.statSync(@path).isDirectory() + throw new Error("#{@path} is a directory") setPath: (@path) -> getPath: -> @path getBaseName: -> - fs.base(@path) + fsUtils.base(@path) write: (text) -> previouslyExisted = @exists() @cachedContents = text - fs.write(@getPath(), text) + fsUtils.write(@getPath(), text) @subscribeToNativeChangeEvents() if not previouslyExisted and @subscriptionCount() > 0 read: (flushCache)-> if not @exists() @cachedContents = null else if not @cachedContents? or flushCache - @cachedContents = fs.read(@getPath()) + @cachedContents = fsUtils.read(@getPath()) else @cachedContents exists: -> - fs.exists(@getPath()) + fsUtils.exists(@getPath()) afterSubscribe: -> @subscribeToNativeChangeEvents() if @exists() and @subscriptionCount() == 1 @@ -67,7 +69,7 @@ class File @trigger "removed" subscribeToNativeChangeEvents: -> - @watchSubscription = fs.watchPath @path, (eventType, path) => + @watchSubscription = fsUtils.watchPath @path, (eventType, path) => @handleNativeChangeEvent(eventType, path) unsubscribeFromNativeChangeEvents: ->