Skip to content

Commit

Permalink
Use openBinaryTempFile from file-io
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Aug 10, 2024
1 parent 6045b93 commit 8ed59b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions System/Directory/OsPath.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE QuasiQuotes #-}

-----------------------------------------------------------------------------
-- |
-- Module : System.Directory.OsPath
Expand Down Expand Up @@ -105,13 +107,13 @@ module System.Directory.OsPath
import Prelude ()
import System.Directory.Internal
import System.Directory.Internal.Prelude
import System.OsString (osstr)
import qualified System.File.OsPath as OS
import System.OsPath
( (<.>)
, (</>)
, addTrailingPathSeparator
, decodeFS
, dropTrailingPathSeparator
, encodeFS
, hasTrailingPathSeparator
, isAbsolute
, joinPath
Expand Down Expand Up @@ -749,13 +751,7 @@ withReplacementFile :: OsPath -- ^ Destination file
withReplacementFile path postAction action =
(`ioeAddLocation` "withReplacementFile") `modifyIOError` do
mask $ \ restore -> do
-- TODO: AFPP doesn't support openBinaryTempFile yet,
-- so we have to use this (sad) workaround
-- (on unix, converts using filesystem encoding, on windows
-- converts with UTF-16LE)
d <- decodeFS (takeDirectory path)
(tmpFPath', hTmp) <- openBinaryTempFile d ".copyFile.tmp"
tmpFPath <- encodeFS tmpFPath'
(tmpFPath, hTmp) <- OS.openBinaryTempFile (takeDirectory path) [osstr|.copyFile.tmp|]
(`onException` ignoreIOExceptions (removeFile tmpFPath)) $ do
r <- (`onException` ignoreIOExceptions (hClose hTmp)) $ do
restore (action hTmp)
Expand Down
2 changes: 1 addition & 1 deletion directory.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Library

build-depends:
base >= 4.12.0 && < 4.21,
file-io >= 0.1.2 && < 0.2,
file-io >= 0.1.3 && < 0.2,
time >= 1.8.0 && < 1.15,
if os(windows)
build-depends: Win32 >= 2.13.3 && < 2.15
Expand Down

0 comments on commit 8ed59b8

Please sign in to comment.