зеркало из https://github.com/microsoft/scalar.git
ProcessHelper: account for platform differences in program locater
Currently, this is hardcoded to run the "where" program, which is not appropriate on non-Windows platforms. Add a platform abstraction so different platforms can run different programs.
This commit is contained in:
Родитель
8fbc67c8e9
Коммит
30f1e87bb6
|
@ -106,6 +106,8 @@ namespace GVFS.Common
|
|||
|
||||
public abstract string GVFSExecutableName { get; }
|
||||
|
||||
public abstract string ProgramLocaterCommand { get; }
|
||||
|
||||
public string GVFSHooksExecutableName
|
||||
{
|
||||
get { return "GVFS.Hooks" + this.ExecutableExtension; }
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace GVFS.Upgrader
|
|||
|
||||
protected virtual bool TryRunGVFSWithArgs(string args, out string consoleError)
|
||||
{
|
||||
string gvfsDirectory = ProcessHelper.WhereDirectory(GVFSPlatform.Instance.Constants.GVFSExecutableName);
|
||||
string gvfsDirectory = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSExecutableName);
|
||||
if (!string.IsNullOrEmpty(gvfsDirectory))
|
||||
{
|
||||
string gvfsPath = Path.Combine(gvfsDirectory, GVFSPlatform.Instance.Constants.GVFSExecutableName);
|
||||
|
|
|
@ -62,9 +62,9 @@ namespace GVFS.Common
|
|||
return currentVersion.Major == 0;
|
||||
}
|
||||
|
||||
public static string WhereDirectory(string processName)
|
||||
public static string GetProgramLocation(string programLocaterCommand, string processName)
|
||||
{
|
||||
ProcessResult result = ProcessHelper.Run("where", processName);
|
||||
ProcessResult result = ProcessHelper.Run(programLocaterCommand, processName);
|
||||
if (result.ExitCode != 0)
|
||||
{
|
||||
return null;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace GVFS.PerfProfiling
|
|||
private GVFSEnlistment CreateEnlistment(string enlistmentRootPath)
|
||||
{
|
||||
string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();
|
||||
string hooksPath = ProcessHelper.WhereDirectory(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
|
||||
string hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
|
||||
|
||||
return GVFSEnlistment.CreateFromDirectory(enlistmentRootPath, gitBinPath, hooksPath, authentication: null);
|
||||
}
|
||||
|
|
|
@ -199,6 +199,12 @@ namespace GVFS.Platform.POSIX
|
|||
{
|
||||
get { return "gvfs"; }
|
||||
}
|
||||
|
||||
public override string ProgramLocaterCommand
|
||||
{
|
||||
get { return "which"; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace GVFS.Platform.Windows
|
|||
return File.Exists(gitBinPath);
|
||||
}
|
||||
|
||||
return ProcessHelper.WhereDirectory(GitProcessName) != null;
|
||||
return ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GitProcessName) != null;
|
||||
}
|
||||
|
||||
public string GetInstalledGitBinPath()
|
||||
|
@ -37,4 +37,4 @@ namespace GVFS.Platform.Windows
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,7 +244,7 @@ namespace GVFS.Platform.Windows
|
|||
{
|
||||
error = null;
|
||||
hooksVersion = null;
|
||||
hooksPath = ProcessHelper.WhereDirectory(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
|
||||
hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
|
||||
if (hooksPath == null)
|
||||
{
|
||||
error = "Could not find " + GVFSPlatform.Instance.Constants.GVFSHooksExecutableName;
|
||||
|
@ -447,6 +447,11 @@ namespace GVFS.Platform.Windows
|
|||
{
|
||||
get { return "GVFS" + this.ExecutableExtension; }
|
||||
}
|
||||
|
||||
public override string ProgramLocaterCommand
|
||||
{
|
||||
get { return "where"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,6 +201,11 @@ namespace GVFS.UnitTests.Mock.Common
|
|||
{
|
||||
get { return "MockGVFS" + this.ExecutableExtension; }
|
||||
}
|
||||
|
||||
public override string ProgramLocaterCommand
|
||||
{
|
||||
get { return "MockWhere"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1110,7 +1110,7 @@ You can specify a URL, a name of a configured cache server, or the special names
|
|||
// the .git/hooks folder, and once Windows does the same, this hooksPath can be removed (from here
|
||||
// and all the classes that handle it on the way to GitProcess)
|
||||
|
||||
hooksPath = ProcessHelper.WhereDirectory(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
|
||||
hooksPath = ProcessHelper.GetProgramLocation(GVFSPlatform.Instance.Constants.ProgramLocaterCommand, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
|
||||
if (hooksPath == null)
|
||||
{
|
||||
this.ReportErrorAndExit("Could not find " + GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);
|
||||
|
|
Загрузка…
Ссылка в новой задаче