From 367241f977b102a394be348f176c9688f1130f42 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 10 Aug 2024 18:31:45 +0800 Subject: [PATCH] Use openBinaryTempFile from file-io --- .github/workflows/build.yml | 11 +++++------ System/Directory/OsPath.hs | 14 +++++--------- directory.cabal | 6 +++--- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c2838ddc..22e18f45 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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.9.3, 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 }} diff --git a/System/Directory/OsPath.hs b/System/Directory/OsPath.hs index dce71b56..64923773 100644 --- a/System/Directory/OsPath.hs +++ b/System/Directory/OsPath.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE QuasiQuotes #-} + ----------------------------------------------------------------------------- -- | -- Module : System.Directory.OsPath @@ -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 @@ -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) diff --git a/directory.cabal b/directory.cabal index 9921cfa1..088444bd 100644 --- a/directory.cabal +++ b/directory.cabal @@ -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 @@ -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