Skip to content

Commit 408cf09

Browse files
committed
Set executable permissions once instead of multiple times
1 parent 48b4891 commit 408cf09

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

hnix-store-nar/src/System/Nix/Nar/Effects.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ streamStringOutIO
8888
streamStringOutIO f executable getChunk =
8989
Exception.Lifted.bracket
9090
(liftIO $ IO.openFile f WriteMode)
91-
(liftIO . IO.hClose)
91+
(\h -> liftIO (updateExecutablePermissions >> IO.hClose h))
9292
go
9393
`Exception.Lifted.catch`
9494
cleanupException
@@ -100,10 +100,11 @@ streamStringOutIO f executable getChunk =
100100
Nothing -> pure ()
101101
Just c -> do
102102
liftIO $ Data.ByteString.hPut handle c
103-
Control.Monad.when (executable == Executable) $ liftIO $ do
104-
p <- Directory.getPermissions f
105-
Directory.setPermissions f (p { Directory.executable = True })
106103
go handle
104+
updateExecutablePermissions =
105+
Control.Monad.when (executable == Executable) $ do
106+
p <- Directory.getPermissions f
107+
Directory.setPermissions f (p { Directory.executable = True })
107108
cleanupException (e :: Exception.Lifted.SomeException) = do
108109
liftIO $ Directory.removeFile f
109110
Control.Monad.fail $

0 commit comments

Comments
 (0)