Skip to content

Commit 6e15b6b

Browse files
committed
Fix HookRunner to check if file is already executable on read-only file systems
1 parent 5fd7e54 commit 6e15b6b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/ES.SFTP.Host/SSH/HookRunner.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,21 @@ private async Task RunHook(string hook, string args = null)
5050
return;
5151
}
5252

53+
var execPermissionOutput = await ProcessUtil.QuickRun("bash",
54+
$"-c \"if [[ -x {hook} ]]; then echo 'true'; else echo 'false'; fi\"", false);
55+
56+
if (execPermissionOutput.ExitCode != 0 ||
57+
!bool.TryParse(execPermissionOutput.Output, out var isExecutable) ||
58+
!isExecutable)
59+
{
60+
await ProcessUtil.QuickRun("chmod", $"+x {hook}");
61+
}
62+
5363
_logger.LogDebug("Executing hook '{hook}'", hook);
54-
await ProcessUtil.QuickRun("chmod", $"+x {hook}");
5564
var hookRun = await ProcessUtil.QuickRun(hook, args, false);
65+
var a = new FileInfo(hook);
66+
67+
5668
if (string.IsNullOrWhiteSpace(hookRun.Output))
5769
_logger.LogDebug("Hook '{hook}' completed with exit code {exitCode}.", hook, hookRun.ExitCode);
5870
else

0 commit comments

Comments
 (0)