Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/JQ/JQ.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -44,21 +45,31 @@ static JQ()
Debug.Assert(File.Exists(jqpath));

#if NET8_0_OR_GREATER
if (!OperatingSystem.IsWindows() && !File.GetUnixFileMode(jqpath).HasFlag(UnixFileMode.UserExecute))
if (!OperatingSystem.IsWindows())
{
#pragma warning disable CA1416 // Validate platform compatibility
try
{
File.SetUnixFileMode(jqpath, UnixFileMode.UserExecute);
Process.Start(jqpath, "--version").WaitForExit();
}
catch (UnauthorizedAccessException)
catch (Win32Exception)
{
// In hosted environments, we might not be able to set the file mode.
// So try using the temp directory instead by first copying the file there.
var tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "jq");
File.Copy(jqpath, tempPath, overwrite: true);
jqpath = tempPath;
File.SetUnixFileMode(jqpath, UnixFileMode.UserExecute);
try
{
File.SetUnixFileMode(jqpath, UnixFileMode.UserExecute);
Process.Start(jqpath, "--version").WaitForExit();
}
catch (UnauthorizedAccessException)
{
// In hosted environments, we might not be able to set the file mode.
// So try using the temp directory instead by first copying the file there.
var tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "jq");
File.Copy(jqpath, tempPath, overwrite: true);
jqpath = tempPath;
File.SetUnixFileMode(jqpath, UnixFileMode.UserExecute);
}
}
#pragma warning restore CA1416 // Validate platform compatibility
}
#endif
}
Expand Down
Loading