Allow ENOENT errors in project.open

This commit is contained in:
Ben Ogle
2015-01-13 14:19:27 -08:00
parent cbd42ac20c
commit 3454249b58
3 changed files with 17 additions and 17 deletions

View File

@@ -287,16 +287,14 @@ describe "Workspace", ->
expect(notification.getMessage()).toContain '< 2MB'
describe "when a file does not exist", ->
it "creates a notification", ->
it "creates an empty buffer for the specified path", ->
waitsForPromise ->
workspace.open('not-a-file.md')
runs ->
expect(notificationSpy).toHaveBeenCalled()
notification = notificationSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'warning'
expect(notification.getMessage()).toContain 'No such file'
expect(notification.getMessage()).toContain 'not-a-file.md'
editor = workspace.getActiveTextEditor()
expect(notificationSpy).not.toHaveBeenCalled()
expect(editor.getPath()).toContain 'not-a-file.md'
describe "when the user does not have access to the file", ->
beforeEach ->

View File

@@ -218,9 +218,12 @@ class Project extends Model
filePath = @resolvePath(filePath)
if filePath?
# Make sure we have permissions
fileDescriptor = fs.openSync(filePath, 'r+')
fs.closeSync(fileDescriptor)
try
fileDescriptor = fs.openSync(filePath, 'r+')
fs.closeSync(fileDescriptor)
catch error
# allow ENOENT errors to create an editor for paths that dont exist
throw error unless error.code is 'ENOENT'
@bufferForPath(filePath).then (buffer) =>
@buildEditorForBuffer(buffer, options)

View File

@@ -451,14 +451,13 @@ class Workspace extends Model
try
item ?= atom.project.open(uri, options)
catch error
if error.code is 'EFILETOOLARGE'
atom.notifications.addWarning("#{error.message} Large file support is being tracked at [atom/atom#307](https://github.com/atom/atom/issues/307).")
else if error.code is 'ENOENT' and error.path?
atom.notifications.addWarning("No such file '#{error.path}'")
else if error.code is 'EACCES' and error.path?
atom.notifications.addWarning("Permission denied '#{error.path}'")
else
throw error
switch error.code
when 'EFILETOOLARGE'
atom.notifications.addWarning("#{error.message} Large file support is being tracked at [atom/atom#307](https://github.com/atom/atom/issues/307).")
when 'EACCES'
atom.notifications.addWarning("Permission denied '#{error.path}'")
else
throw error
return Q()
Q(item)