Skip to content

Fix import warning #5087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions cardano-api/src/Cardano/Api/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ module Cardano.Api.IO
#ifdef UNIX
import Control.Exception (IOException, bracket, bracketOnError, try)
import System.Directory ()
import System.IO (hClose)
import System.Posix.Files (ownerModes, setFdOwnerAndGroup)
import System.Posix.IO (OpenMode (..), closeFd, defaultFileFlags, fdToHandle, openFd)
import System.Posix.User (getRealUserID)
#else
import Control.Exception (bracketOnError)
import System.Directory (removeFile, renameFile)
import System.FilePath (splitFileName, (<.>))
import System.IO (hClose, openTempFile)
#endif

import Cardano.Api.Error (FileError (..))
Expand All @@ -54,6 +52,7 @@ import Data.String (IsString)
import Data.Text (Text)
import qualified Data.Text.IO as Text
import GHC.Generics (Generic)
import qualified System.IO as IO
import System.IO (Handle)

handleFileForWritingWithOwnerPermission
Expand All @@ -80,20 +79,20 @@ handleFileForWritingWithOwnerPermission path f = do
Right fd -> do
bracket
(fdToHandle fd)
hClose
IO.hClose
(runExceptT . handleIOExceptT (FileIOError path) . f)
#else
-- On something other than unix, we make a _new_ file, and since we created it,
-- we must own it. We then place it at the target location. Unfortunately this
-- won't work correctly with pseudo-files.
bracketOnError
(openTempFile targetDir $ targetFile <.> "tmp")
(IO.openTempFile targetDir $ targetFile <.> "tmp")
(\(tmpPath, h) -> do
hClose h >> removeFile tmpPath
IO.hClose h >> removeFile tmpPath
return . Left $ FileErrorTempFile path tmpPath h)
(\(tmpPath, h) -> do
f h
hClose h
IO.hClose h
renameFile tmpPath path
return $ Right ())
where
Expand Down