Bare minimum fix to the default directory provider

This commit is contained in:
Mostafa Eweda
2015-03-02 14:28:01 -08:00
parent ed8433cda4
commit b74a688baa
3 changed files with 22 additions and 14 deletions

View File

@@ -78,6 +78,20 @@ describe "Project", ->
expect(directories.length).toBe 1
expect(directories[0].getPath()).toBe tmp
it "gets the parent directory from the default directory provider if it's a local directory", ->
tmp = temp.mkdirSync()
atom.project.setPaths([path.join(tmp, "not-existing")])
directories = atom.project.getDirectories()
expect(directories.length).toBe 1
expect(directories[0].getPath()).toBe tmp
it "only normalizes the directory path if it isn't on the local filesystem", ->
nonLocalFsDirectory = "custom_proto://abc/def"
atom.project.setPaths([nonLocalFsDirectory])
directories = atom.project.getDirectories()
expect(directories.length).toBe 1
expect(directories[0].getPath()).toBe path.normalize(nonLocalFsDirectory)
it "tries to update repositories when a new RepositoryProvider is registered", ->
tmp = temp.mkdirSync('atom-project')
atom.project.setPaths([tmp])

View File

@@ -16,15 +16,12 @@ class DefaultDirectoryProvider
directoryForURISync: (uri) ->
projectPath = path.normalize(uri)
directoryPath = if fs.isDirectorySync(projectPath)
projectPath
else
directoryPath = if !fs.isDirectorySync(projectPath) and fs.isDirectorySync(path.dirname(projectPath))
path.dirname(projectPath)
if fs.isDirectorySync(projectPath)
return new Directory(directoryPath)
else
return null
projectPath
new Directory(directoryPath)
# Public: Create a Directory that corresponds to the specified URI.
#

View File

@@ -39,7 +39,6 @@ class Project extends Model
@emitter = new Emitter
@buffers ?= []
@rootDirectories = []
@packageRootDirectoryPaths = []
@repositories = []
@directoryProviders = [new DefaultDirectoryProvider()]
@@ -204,12 +203,10 @@ class Project extends Model
for provider in @directoryProviders
break if directory = provider.directoryForURISync?(projectPath)
if directory is null
# DefaultDirectoryProvider doesn't handle specific directory protocols
# Atom Packages may use packageDirectoryPaths to add their own paths later.
@packageRootDirectoryPaths.push(projectPath)
return
else
@rootDirectories.push(directory)
# This should never happen because DefaultDirectoryProvider should always
# return a Directory.
throw new Error(projectPath + ' could not be resolved to a directory')
@rootDirectories.push(directory)
repo = null
for provider in @repositoryProviders