From 867f920329641a704d9854c906b0cf04945bea94 Mon Sep 17 00:00:00 2001 From: postcasio Date: Tue, 20 Jan 2015 09:52:12 +0000 Subject: [PATCH] Handle EROFS errors when saving --- spec/workspace-spec.coffee | 15 +++++++++++++++ src/workspace.coffee | 2 ++ 2 files changed, 17 insertions(+) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 4dcfa13ce..b9642e17d 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -1008,6 +1008,21 @@ describe "Workspace", -> expect(notificaiton.getType()).toBe 'warning' expect(notificaiton.getMessage()).toContain 'Unable to save' + it "emits a warning notification when the file system is read-only", -> + spyOn(Pane::, 'saveActiveItem').andCallFake -> + error = new Error("EROFS, read-only file system '/Some/dir/and-a-file.js'") + error.code = 'EROFS' + error.path = '/Some/dir/and-a-file.js' + throw error + + atom.notifications.onDidAddNotification addedSpy = jasmine.createSpy() + atom.workspace.saveActivePaneItem() + expect(addedSpy).toHaveBeenCalled() + + notification = addedSpy.mostRecentCall.args[0] + expect(notification.getType()).toBe 'warning' + expect(notification.getMessage()).toContain 'Unable to save' + it "emits a warning notification when the file cannot be saved", -> spyOn(Pane::, 'saveActiveItem').andCallFake -> throw new Error("no one knows") diff --git a/src/workspace.coffee b/src/workspace.coffee index 51e1584dc..68db4d2d4 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -631,6 +631,8 @@ class Workspace extends Model 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 error.code is 'EROFS' and error.path? + atom.notifications.addWarning("Unable to save file: Read-only file system '#{error.path}'") 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")