mirror of
https://github.com/actions/runner.git
synced 2025-12-14 04:53:34 +00:00
GitHub Actions Runner
This commit is contained in:
36
src/Runner.Sdk/Util/PathUtil.cs
Normal file
36
src/Runner.Sdk/Util/PathUtil.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace GitHub.Runner.Sdk
|
||||
{
|
||||
public static class PathUtil
|
||||
{
|
||||
#if OS_WINDOWS
|
||||
public static readonly string PathVariable = "Path";
|
||||
#else
|
||||
public static readonly string PathVariable = "PATH";
|
||||
#endif
|
||||
|
||||
public static string PrependPath(string path, string currentPath)
|
||||
{
|
||||
ArgUtil.NotNullOrEmpty(path, nameof(path));
|
||||
if (string.IsNullOrEmpty(currentPath))
|
||||
{
|
||||
// Careful not to add a trailing separator if the PATH is empty.
|
||||
// On OSX/Linux, a trailing separator indicates that "current directory"
|
||||
// is added to the PATH, which is considered a security risk.
|
||||
return path;
|
||||
}
|
||||
|
||||
// Not prepend path if it is already the first path in %PATH%
|
||||
if (currentPath.StartsWith(path + Path.PathSeparator, IOUtil.FilePathStringComparison))
|
||||
{
|
||||
return currentPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return path + Path.PathSeparator + currentPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user