Post a notification when the user cannot access a file

This commit is contained in:
Ben Ogle
2015-01-07 16:01:23 -08:00
parent 4138b95146
commit ca1f66d197
3 changed files with 27 additions and 0 deletions

View File

@@ -297,6 +297,26 @@ describe "Workspace", ->
expect(notification.getMessage()).toContain 'No such file'
expect(notification.getMessage()).toContain 'not-a-file.md'
describe "when the user does not have access to the file", ->
beforeEach ->
spyOn(fs, 'openSync').andCallFake (path)->
error = new Error("EACCES, permission denied '#{path}'")
error.path = path
error.code = 'EACCES'
throw error
it "creates a notification", ->
waitsForPromise ->
workspace.open('file1', workspace.getActivePane())
runs ->
expect(notificationSpy).toHaveBeenCalled()
notification = notificationSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'warning'
expect(notification.getMessage()).toContain 'Permission denied'
expect(notification.getMessage()).toContain 'file1'
describe "::reopenItem()", ->
it "opens the uri associated with the last closed pane that isn't currently open", ->
pane = workspace.getActivePane()

View File

@@ -218,6 +218,11 @@ class Project extends Model
# Returns a promise that resolves to an {TextEditor}.
open: (filePath, options={}) ->
filePath = @resolvePath(filePath)
# Make sure we have permissions
fileDescriptor = fs.openSync(filePath, 'r+')
fs.closeSync(fileDescriptor)
@bufferForPath(filePath).then (buffer) =>
@buildEditorForBuffer(buffer, options)

View File

@@ -455,6 +455,8 @@ class Workspace extends Model
atom.notifications.addWarning(error.message)
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}'")
return Q()
Q(item)