Skip to content

Commit

Permalink
Fix HookRunner to check if file is already executable on read-only fi…
Browse files Browse the repository at this point in the history
…le systems
  • Loading branch information
winromulus committed Jul 9, 2020
1 parent 5fd7e54 commit 6e15b6b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ES.SFTP.Host/SSH/HookRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,21 @@ private async Task RunHook(string hook, string args = null)
return;
}

var execPermissionOutput = await ProcessUtil.QuickRun("bash",
$"-c \"if [[ -x {hook} ]]; then echo 'true'; else echo 'false'; fi\"", false);

if (execPermissionOutput.ExitCode != 0 ||
!bool.TryParse(execPermissionOutput.Output, out var isExecutable) ||
!isExecutable)
{
await ProcessUtil.QuickRun("chmod", $"+x {hook}");
}

_logger.LogDebug("Executing hook '{hook}'", hook);
await ProcessUtil.QuickRun("chmod", $"+x {hook}");
var hookRun = await ProcessUtil.QuickRun(hook, args, false);
var a = new FileInfo(hook);


if (string.IsNullOrWhiteSpace(hookRun.Output))
_logger.LogDebug("Hook '{hook}' completed with exit code {exitCode}.", hook, hookRun.ExitCode);
else
Expand Down

0 comments on commit 6e15b6b

Please sign in to comment.