diff --git a/src/GitHub.Api/IO/NiceIO.cs b/src/GitHub.Api/IO/NiceIO.cs index 2e94b06e7..91ee6041e 100644 --- a/src/GitHub.Api/IO/NiceIO.cs +++ b/src/GitHub.Api/IO/NiceIO.cs @@ -697,6 +697,18 @@ public static NPath CreateTempDirectory(string myprefix) } } + public static NPath GetTempFilename(string myprefix = "") + { + var random = new Random(); + var prefix = FileSystem.GetTempPath() + "/" + (String.IsNullOrEmpty(myprefix) ? "" : myprefix + "_"); + while (true) + { + var candidate = new NPath(prefix + random.Next()); + if (!candidate.Exists()) + return candidate; + } + } + public NPath Move(string dest) { return Move(new NPath(dest)); diff --git a/src/GitHub.Api/OutputProcessors/ProcessManager.cs b/src/GitHub.Api/OutputProcessors/ProcessManager.cs index a5787c2c1..83965f350 100644 --- a/src/GitHub.Api/OutputProcessors/ProcessManager.cs +++ b/src/GitHub.Api/OutputProcessors/ProcessManager.cs @@ -76,7 +76,8 @@ public void RunCommandLineWindow(NPath workingDirectory) { // we need to create a temp bash script to set up the environment properly, because // osx terminal app doesn't inherit the PATH env var and there's no way to pass it in - var envVarFile = environment.FileSystem.GetRandomFileName(); + + var envVarFile = NPath.GetTempFilename(); environment.FileSystem.WriteAllLines(envVarFile, new string[] { "cd $GHU_WORKINGDIR", "PATH=$GHU_FULLPATH:$PATH /bin/bash" }); Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755) startInfo.FileName = "open";