Set executable permissions once instead of multiple times

This commit is contained in:
Vaibhav Sagar 2023-11-26 15:42:52 +11:00
parent 48b4891693
commit 408cf093ea

View File

@ -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 $