|
1 | 1 | {-# LANGUAGE CPP #-}
|
| 2 | +{-# LANGUAGE TypeApplications #-} |
2 | 3 |
|
3 | 4 | -----------------------------------------------------------------------------
|
4 | 5 | -- |
|
@@ -40,12 +41,12 @@ import Foreign.C hiding (
|
40 | 41 |
|
41 | 42 | import System.OsPath.Types
|
42 | 43 | import Control.Monad
|
43 |
| -import GHC.IO.Encoding.UTF8 ( mkUTF8 ) |
44 |
| -import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) |
45 |
| -import System.OsPath.Posix |
| 44 | +import Control.Exception |
| 45 | +import System.OsPath.Posix as PS |
46 | 46 | import System.OsPath.Data.ByteString.Short
|
47 | 47 | import Prelude hiding (FilePath)
|
48 | 48 | import System.OsString.Internal.Types (PosixString(..))
|
| 49 | + |
49 | 50 | #if !MIN_VERSION_base(4, 11, 0)
|
50 | 51 | import Data.Monoid ((<>))
|
51 | 52 | #endif
|
@@ -93,7 +94,8 @@ throwErrnoPath :: String -> PosixPath -> IO a
|
93 | 94 | throwErrnoPath loc path =
|
94 | 95 | do
|
95 | 96 | errno <- getErrno
|
96 |
| - ioError (errnoToIOError loc errno Nothing (Just (_toStr path))) |
| 97 | + path' <- either (const (_toStr path)) id <$> try @IOException (PS.decodeFS path) |
| 98 | + ioError (errnoToIOError loc errno Nothing (Just path')) |
97 | 99 |
|
98 | 100 | -- | as 'throwErrnoIf', but exceptions include the given path when
|
99 | 101 | -- appropriate.
|
@@ -131,10 +133,10 @@ throwErrnoPathIfMinus1_ = throwErrnoPathIf_ (== -1)
|
131 | 133 | -- | as 'throwErrnoTwoPathsIfMinus1_', but exceptions include two paths when appropriate.
|
132 | 134 | --
|
133 | 135 | throwErrnoTwoPathsIfMinus1_ :: (Eq a, Num a) => String -> PosixPath -> PosixPath -> IO a -> IO ()
|
134 |
| -throwErrnoTwoPathsIfMinus1_ loc path1 path2 = |
135 |
| - throwErrnoIfMinus1_ (loc <> " '" <> _toStr path1 <> "' to '" <> _toStr path2 <> "'") |
136 |
| - |
| 136 | +throwErrnoTwoPathsIfMinus1_ loc path1 path2 action = do |
| 137 | + path1' <- either (const (_toStr path1)) id <$> try @IOException (PS.decodeFS path1) |
| 138 | + path2' <- either (const (_toStr path2)) id <$> try @IOException (PS.decodeFS path2) |
| 139 | + throwErrnoIfMinus1_ (loc <> " '" <> path1' <> "' to '" <> path2' <> "'") action |
137 | 140 |
|
138 | 141 | _toStr :: PosixPath -> String
|
139 |
| -_toStr fp = either (error . show) id $ decodeWith (mkUTF8 TransliterateCodingFailure) fp |
140 |
| - |
| 142 | +_toStr = fmap PS.toChar . PS.unpack |
0 commit comments