Wrap 7za so a "Cannot create symbolic link" failure on libcrypto/libssl .dylib entries exits 0 instead of failing the extraction; all other non-zero exits pass through. Also picks up npm lockfile normalization. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
class Shim
|
|
{
|
|
static string Quote(string a)
|
|
{
|
|
if (a.Length > 0 && a.IndexOfAny(new[] { ' ', '\t', '"' }) < 0) return a;
|
|
var sb = new StringBuilder();
|
|
sb.Append('"');
|
|
int backslashes = 0;
|
|
foreach (char c in a)
|
|
{
|
|
if (c == '\\') { backslashes++; continue; }
|
|
if (c == '"') { sb.Append('\\', backslashes * 2 + 1); sb.Append('"'); }
|
|
else { sb.Append('\\', backslashes); sb.Append(c); }
|
|
backslashes = 0;
|
|
}
|
|
sb.Append('\\', backslashes * 2);
|
|
sb.Append('"');
|
|
return sb.ToString();
|
|
}
|
|
|
|
static int Main(string[] args)
|
|
{
|
|
string exeDir = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
|
|
string realExe = Path.Combine(exeDir, "7za-orig.exe");
|
|
|
|
var argLine = new StringBuilder();
|
|
for (int i = 0; i < args.Length; i++)
|
|
{
|
|
if (i > 0) argLine.Append(' ');
|
|
argLine.Append(Quote(args[i]));
|
|
}
|
|
|
|
var psi = new ProcessStartInfo();
|
|
psi.FileName = realExe;
|
|
psi.Arguments = argLine.ToString();
|
|
psi.UseShellExecute = false;
|
|
psi.RedirectStandardOutput = true;
|
|
psi.RedirectStandardError = true;
|
|
psi.CreateNoWindow = true;
|
|
|
|
var stdout = new StringBuilder();
|
|
var stderr = new StringBuilder();
|
|
var p = new Process();
|
|
p.StartInfo = psi;
|
|
p.OutputDataReceived += (s, e) => { if (e.Data != null) { stdout.AppendLine(e.Data); Console.Out.WriteLine(e.Data); } };
|
|
p.ErrorDataReceived += (s, e) => { if (e.Data != null) { stderr.AppendLine(e.Data); Console.Error.WriteLine(e.Data); } };
|
|
p.Start();
|
|
p.BeginOutputReadLine();
|
|
p.BeginErrorReadLine();
|
|
p.WaitForExit();
|
|
|
|
int code = p.ExitCode;
|
|
if (code == 0) return 0;
|
|
|
|
string combined = stderr.ToString() + "\n" + stdout.ToString();
|
|
bool hasSymlinkErr = combined.IndexOf("Cannot create symbolic link", StringComparison.OrdinalIgnoreCase) >= 0;
|
|
bool dylibMentioned =
|
|
combined.IndexOf("libcrypto.dylib", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
combined.IndexOf("libssl.dylib", StringComparison.OrdinalIgnoreCase) >= 0;
|
|
|
|
if (hasSymlinkErr && dylibMentioned) return 0;
|
|
return code;
|
|
}
|
|
}
|