Merge pull request #13725 from hron/normalize-disk-drive-letter

Normalize disk drive letter in path on Windows
This commit is contained in:
Damien Guard
2017-02-04 17:51:40 -08:00
committed by GitHub
4 changed files with 29 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ class DefaultDirectoryProvider
# * {Directory} if the given URI is compatible with this provider.
# * `null` if the given URI is not compatibile with this provider.
directoryForURISync: (uri) ->
normalizedPath = path.normalize(uri)
normalizedPath = @normalizePath(uri)
{host} = url.parse(uri)
directoryPath = if host
uri
@@ -42,3 +42,15 @@ class DefaultDirectoryProvider
# * `null` if the given URI is not compatibile with this provider.
directoryForURI: (uri) ->
Promise.resolve(@directoryForURISync(uri))
# Public: Normalizes path.
#
# * `uri` {String} The path that should be normalized.
#
# Returns a {String} with normalized path.
normalizePath: (uri) ->
# Normalize disk drive letter on Windows to avoid opening two buffers for the same file
pathWithNormalizedDiskDriveLetter = uri
if matchData = uri.match(/^([A-Za-z]):/)
pathWithNormalizedDiskDriveLetter = "#{matchData[1].toUpperCase()}#{uri.slice(1)}"
path.normalize(pathWithNormalizedDiskDriveLetter)

View File

@@ -208,7 +208,7 @@ class Project extends Model
removePath: (projectPath) ->
# The projectPath may be a URI, in which case it should not be normalized.
unless projectPath in @getPaths()
projectPath = path.normalize(projectPath)
projectPath = @defaultDirectoryProvider.normalizePath(projectPath)
indexToRemove = null
for directory, i in @rootDirectories
@@ -236,11 +236,10 @@ class Project extends Model
uri
else
if fs.isAbsolute(uri)
path.normalize(fs.resolveHome(uri))
@defaultDirectoryProvider.normalizePath(fs.resolveHome(uri))
# TODO: what should we do here when there are multiple directories?
else if projectPath = @getPaths()[0]
path.normalize(fs.resolveHome(path.join(projectPath, uri)))
@defaultDirectoryProvider.normalizePath(fs.resolveHome(path.join(projectPath, uri)))
else
undefined