From 408cf093eaca70a0e4cde616a86bc02f31a94c86 Mon Sep 17 00:00:00 2001 From: Vaibhav Sagar Date: Sun, 26 Nov 2023 15:42:52 +1100 Subject: [PATCH] Set executable permissions once instead of multiple times --- hnix-store-nar/src/System/Nix/Nar/Effects.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hnix-store-nar/src/System/Nix/Nar/Effects.hs b/hnix-store-nar/src/System/Nix/Nar/Effects.hs index 50f9870..ff0a874 100644 --- a/hnix-store-nar/src/System/Nix/Nar/Effects.hs +++ b/hnix-store-nar/src/System/Nix/Nar/Effects.hs @@ -88,7 +88,7 @@ streamStringOutIO streamStringOutIO f executable getChunk = Exception.Lifted.bracket (liftIO $ IO.openFile f WriteMode) - (liftIO . IO.hClose) + (\h -> liftIO (updateExecutablePermissions >> IO.hClose h)) go `Exception.Lifted.catch` cleanupException @@ -100,10 +100,11 @@ streamStringOutIO f executable getChunk = Nothing -> pure () Just c -> do liftIO $ Data.ByteString.hPut handle c - Control.Monad.when (executable == Executable) $ liftIO $ do - p <- Directory.getPermissions f - Directory.setPermissions f (p { Directory.executable = True }) go handle + updateExecutablePermissions = + Control.Monad.when (executable == Executable) $ do + p <- Directory.getPermissions f + Directory.setPermissions f (p { Directory.executable = True }) cleanupException (e :: Exception.Lifted.SomeException) = do liftIO $ Directory.removeFile f Control.Monad.fail $