Support TildeSlash expand (#8589)

This commit is contained in:
William Lee 2018-02-12 14:59:43 -08:00 committed by GitHub
parent 72d9c0f23f
commit 2a493c1318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Cli.Utils
private static char[] s_pathSeparator = new char[] { Path.PathSeparator };
private static char[] s_quote = new char[] { '"' };
private IEnumerable<string> _searchPaths;
private readonly Lazy<string> _userHomeDirectory = new Lazy<string>(() => Environment.GetEnvironmentVariable("HOME") ?? string.Empty);
private IEnumerable<string> _executableExtensions;
public IEnumerable<string> ExecutableExtensions
@ -45,7 +46,8 @@ namespace Microsoft.DotNet.Cli.Utils
searchPaths.AddRange(Environment
.GetEnvironmentVariable("PATH")
.Split(s_pathSeparator)
.Select(p => p.Trim(s_quote)));
.Select(p => p.Trim(s_quote))
.Select(p => ExpandTildeSlash(p)));
_searchPaths = searchPaths;
}
@ -54,6 +56,19 @@ namespace Microsoft.DotNet.Cli.Utils
}
}
private string ExpandTildeSlash(string path)
{
const string tildeSlash = "~/";
if (path.StartsWith(tildeSlash, StringComparison.Ordinal) && !string.IsNullOrEmpty(_userHomeDirectory.Value))
{
return Path.Combine(_userHomeDirectory.Value, path.Substring(tildeSlash.Length));
}
else
{
return path;
}
}
public EnvironmentProvider(
IEnumerable<string> extensionsOverride = null,
IEnumerable<string> searchPathsOverride = null)