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 f525e77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ jobs:
fail-fast: false
matrix:
include:
- { os: macOS-13, stack: lts-13.30, stack-extra-deps: "bytestring-0.11.3.0, file-io-0.1.2, filepath-1.4.100.0, unix-2.8.0.0" }
- { os: macos-latest, stack: lts-22.7, stack-extra-deps: "bytestring-0.11.5.3, file-io-0.1.2, filepath-1.5.2.0, os-string-2.0.2, unix-2.8.5.1", stack-package-flags: "{directory: {os-string: true}, file-io: {os-string: true}, unix: {os-string: true}}", ghc-flags: -Werror=deprecations }
- { os: ubuntu-latest, ghc: 8.6.5, cabal: 3.0.0.0, overrides: "before_prepare() { sed -i.bak /utimensat/d configure.ac; }" }
- { os: macOS-13, stack: lts-15.3, stack-extra-deps: "bytestring-0.11.3.0, file-io-0.1.4, filepath-1.4.100.0, unix-2.8.0.0" }
- { os: macos-latest, stack: lts-22.7, stack-extra-deps: "bytestring-0.11.5.3, file-io-0.1.4, filepath-1.5.2.0, os-string-2.0.2, unix-2.8.5.1", stack-package-flags: "{directory: {os-string: true}, file-io: {os-string: true}, unix: {os-string: true}}", ghc-flags: -Werror=deprecations }
- { os: ubuntu-latest, ghc: 8.10.7, cabal: 3.8.1.0 }
- { os: ubuntu-latest, ghc: 9.0.2, cabal: 3.8.1.0 }
- { os: ubuntu-latest, ghc: 9.2.4, cabal: 3.8.1.0 }
- { os: ubuntu-latest, ghc: 9.4.3, cabal: 3.8.1.0 }
- { os: ubuntu-latest, ghc: latest, cabal: latest, cabal-package-flags: +os-string, ghc-flags: -Werror=deprecations }
- { os: windows-latest, stack: lts-13.30, stack-extra-deps: "bytestring-0.11.3.0, file-io-0.1.2, filepath-1.4.100.0, time-1.8.0.2, Win32-2.13.3.0", overrides: "before_prepare() { sed -i.bak -e /CreateSymbolicLinkW/d -e /GetFinalPathNameByHandleW/d configure.ac; }" }
- { os: windows-latest, stack: lts-17.5, stack-extra-deps: "bytestring-0.11.3.0, file-io-0.1.2, filepath-1.4.100.0, time-1.9.3, Win32-2.13.3.0" }
- { os: windows-latest, stack: lts-22.7, stack-extra-deps: "bytestring-0.11.5.3, file-io-0.1.2, filepath-1.5.2.0, os-string-2.0.2, time-1.14, Win32-2.14.0.0", stack-package-flags: "{directory: {os-string: true}, file-io: {os-string: true}, Win32: {os-string: true}}", ghc-flags: -Werror=deprecations }
- { os: windows-latest, stack: lts-15.3, stack-extra-deps: "bytestring-0.11.3.0, file-io-0.1.4, filepath-1.4.100.0, time-1.8.0.2, Win32-2.13.3.0", overrides: "before_prepare() { sed -i.bak -e /CreateSymbolicLinkW/d -e /GetFinalPathNameByHandleW/d configure.ac; }" }
- { os: windows-latest, stack: lts-17.5, stack-extra-deps: "bytestring-0.11.3.0, file-io-0.1.4, filepath-1.4.100.0, time-1.9.3, Win32-2.13.3.0" }
- { os: windows-latest, stack: lts-22.7, stack-extra-deps: "bytestring-0.11.5.3, file-io-0.1.4, filepath-1.5.2.0, os-string-2.0.2, time-1.14, Win32-2.14.0.0", stack-package-flags: "{directory: {os-string: true}, file-io: {os-string: true}, Win32: {os-string: true}}", ghc-flags: -Werror=deprecations }
runs-on: ${{ matrix.os }}
env:
CABAL_PACKAGE_FLAGS: ${{ matrix.cabal-package-flags }}
Expand Down
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
6 changes: 3 additions & 3 deletions directory.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description:
directories in a portable way.
category: System
build-type: Configure
tested-with: GHC == 8.6.5 || == 8.10.7 || == 9.0.2 || == 9.2.4 || == 9.4.3
tested-with: GHC == 8.10.7 || == 9.0.2 || == 9.2.4 || == 9.4.3

extra-tmp-files:
autom4te.cache
Expand Down Expand Up @@ -59,8 +59,8 @@ Library
include-dirs: .

build-depends:
base >= 4.12.0 && < 4.21,
file-io >= 0.1.2 && < 0.2,
base >= 4.13.0 && < 4.21,
file-io >= 0.1.4 && < 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 f525e77

Please sign in to comment.