Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e957673

Browse files
Merge pull request #231 from github-for-unity/fixes/228-cmdline-tempfiles
Create temp files in the temp directory
2 parents aa86496 + 7ba1e41 commit e957673

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,18 @@ public static NPath CreateTempDirectory(string myprefix)
697697
}
698698
}
699699

700+
public static NPath GetTempFilename(string myprefix = "")
701+
{
702+
var random = new Random();
703+
var prefix = FileSystem.GetTempPath() + "/" + (String.IsNullOrEmpty(myprefix) ? "" : myprefix + "_");
704+
while (true)
705+
{
706+
var candidate = new NPath(prefix + random.Next());
707+
if (!candidate.Exists())
708+
return candidate;
709+
}
710+
}
711+
700712
public NPath Move(string dest)
701713
{
702714
return Move(new NPath(dest));

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void RunCommandLineWindow(NPath workingDirectory)
7676
{
7777
// we need to create a temp bash script to set up the environment properly, because
7878
// osx terminal app doesn't inherit the PATH env var and there's no way to pass it in
79-
var envVarFile = environment.FileSystem.GetRandomFileName();
79+
80+
var envVarFile = NPath.GetTempFilename();
8081
environment.FileSystem.WriteAllLines(envVarFile, new string[] { "cd $GHU_WORKINGDIR", "PATH=$GHU_FULLPATH:$PATH /bin/bash" });
8182
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
8283
startInfo.FileName = "open";

0 commit comments

Comments
 (0)