Skip to content

Commit

Permalink
Cleanup lockfile manually and return if script fails
Browse files Browse the repository at this point in the history
  • Loading branch information
valters-tomsons committed Apr 20, 2023
1 parent 18779c8 commit 587f75a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/DayZLauncher.UnixPatcher.Utils/UnixJunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ private static string RunShellCommand(string command, string arguments)
Directory.CreateDirectory(basePath);

string uniqueId = Guid.NewGuid().ToString("N");
string tempScriptPath = basePath + @$"\tmp_script_{uniqueId}.sh";
string tempOutputPath = basePath + @$"\tmp_output_{uniqueId}.txt";
string lockFilePath = basePath + @$"\{uniqueId}.lock";

Console.WriteLine("UnixJunctions.RunShellCommand: tempScriptPath= " + tempScriptPath + " ;tempOutputPath= " + tempOutputPath);
Console.WriteLine($"UnixJunctions.RunShellCommand: tempOutputPath='{tempOutputPath}'");

var script = $"""
#!/bin/sh
Expand Down Expand Up @@ -124,7 +123,14 @@ private static string RunShellCommand(string command, string arguments)

if (process.ExitCode != 0)
{
throw new Exception($"UnixJunctions: Error running shell script '{tempScriptPath}'. Exit code: {process.ExitCode}");
Console.WriteLine($"UnixJunctions: Error executing script '{uniqueId}'. Exit code: {process.ExitCode}");

if (File.Exists(lockFilePath))
{
Console.WriteLine($"UnixJunctions: Cleaning up {lockFilePath}");
File.Delete(lockFilePath);
return string.Empty;
}
}
}

Expand All @@ -141,12 +147,11 @@ private static string RunShellCommand(string command, string arguments)
}

// Read the output file
string output = File.ReadAllText(tempOutputPath);
Console.WriteLine("UnixJunctions.RunShellCommand: output= " + output);

string scriptOutput = File.ReadAllText(tempOutputPath);
Console.WriteLine($"UnixJunctions.RunShellCommand: {uniqueId} output= {scriptOutput}");
File.Delete(tempOutputPath);

return output;
return scriptOutput;
}

private static string ToUnixPath(string windowsPath)
Expand Down

0 comments on commit 587f75a

Please sign in to comment.