diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index a05125c9f..4dcfa13ce 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -334,6 +334,25 @@ describe "Workspace", -> expect(notification.getMessage()).toContain 'Unable to open' expect(notification.getMessage()).toContain 'file1' + describe "when the the file is already open in windows", -> + beforeEach -> + spyOn(fs, 'openSync').andCallFake (path) -> + error = new Error("EBUSY, resource busy or locked '#{path}'") + error.path = path + error.code = 'EBUSY' + throw error + + it "creates a notification", -> + waitsForPromise -> + workspace.open('file1') + + runs -> + expect(notificationSpy).toHaveBeenCalled() + notification = notificationSpy.mostRecentCall.args[0] + expect(notification.getType()).toBe 'warning' + expect(notification.getMessage()).toContain 'Unable to open' + expect(notification.getMessage()).toContain 'file1' + describe "when there is an unhandled error", -> beforeEach -> spyOn(fs, 'openSync').andCallFake (path) -> @@ -974,10 +993,20 @@ describe "Workspace", -> error.path = '/Some/dir/and-a-file.js' throw error + it "emits a warning notification when the file is already open by another app", -> + spyOn(Pane::, 'saveActiveItem').andCallFake -> + error = new Error("EBUSY, resource busy or locked '/Some/dir/and-a-file.js'") + error.code = 'EBUSY' + error.path = '/Some/dir/and-a-file.js' + throw error + atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy() atom.workspace.saveActivePaneItem() expect(addedSpy).toHaveBeenCalled() - expect(addedSpy.mostRecentCall.args[0].getType()).toBe 'warning' + + notificaiton = addedSpy.mostRecentCall.args[0] + expect(notificaiton.getType()).toBe 'warning' + expect(notificaiton.getMessage()).toContain 'Unable to save' it "emits a warning notification when the file cannot be saved", -> spyOn(Pane::, 'saveActiveItem').andCallFake -> diff --git a/src/workspace.coffee b/src/workspace.coffee index 30a1d3d67..ca01c2694 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -458,6 +458,8 @@ class Workspace extends Model atom.notifications.addWarning("Permission denied '#{error.path}'") when 'EPERM' atom.notifications.addWarning("Unable to open '#{error.path}'", detail: error.message) + when 'EBUSY' + atom.notifications.addWarning("Unable to open '#{error.path}'", detail: error.message) else throw error return Q() @@ -629,6 +631,8 @@ class Workspace extends Model atom.notifications.addWarning("Unable to save file: Permission denied '#{error.path}'") else if error.code is 'EPERM' and error.path? atom.notifications.addWarning("Unable to save file '#{error.path}'", detail: error.message) + else if error.code is 'EBUSY' and error.path? + atom.notifications.addWarning("Unable to save file '#{error.path}'", detail: error.message) else if errorMatch = /ENOTDIR, not a directory '([^']+)'/.exec(error.message) fileName = errorMatch[1] atom.notifications.addWarning("Unable to save file: A directory in the path '#{fileName}' could not be written to")