Don't deserialize buffers with inaccessible paths

This commit is contained in:
Kevin Sawicki
2015-01-15 13:08:16 -08:00
parent 0cf180804c
commit d736ebff38
2 changed files with 21 additions and 5 deletions

View File

@@ -50,6 +50,19 @@ describe "Project", ->
deserializedProject = atom.project.testSerialization()
expect(deserializedProject.getBuffers().length).toBe 0
it "does not deserialize buffers when their path is inaccessible", ->
pathToOpen = path.join(temp.mkdirSync(), 'file.txt')
fs.writeFileSync(pathToOpen, '')
waitsForPromise ->
atom.project.open(pathToOpen)
runs ->
expect(atom.project.getBuffers().length).toBe 1
fs.chmodSync(pathToOpen, '000')
deserializedProject = atom.project.testSerialization()
expect(deserializedProject.getBuffers().length).toBe 0
describe "when an editor is saved and the project has no path", ->
it "sets the project's path to the saved file's parent directory", ->
tempFile = temp.openSync().path

View File

@@ -67,11 +67,14 @@ class Project extends Model
deserializeParams: (params) ->
params.buffers = _.compact params.buffers.map (bufferState) ->
try
atom.deserializers.deserialize(bufferState)
catch error
# Ignore buffers whose previous paths are now folders
throw error unless error.code is 'EISDIR'
# Check that buffer's file path is accessible
if bufferState.filePath
try
fs.closeSync(fs.openSync(bufferState.filePath, 'r+'))
catch error
return unless error.code is 'ENOENT'
atom.deserializers.deserialize(bufferState)
params
###