mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Post a notification when the user cannot access a file
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user