aboutsummaryrefslogtreecommitdiff
path: root/Utility/FileSystemEncoding.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-08-12 10:57:48 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-08-12 10:57:48 -0400
commita607baeb64b7f3e221dcc4856afefbe21c6c9bd2 (patch)
tree79a95f0df3b9c0e0ac13c1d8c63980bef40c512a /Utility/FileSystemEncoding.hs
parent7f9940c1f4a6a533c1d5e7cd7980419f59524ff3 (diff)
avoid throwing exception when String is not encoded using the filesystem encoding
Since _encodeFilePath generates a String that doesn't use the filesystem encoding, when this exception is caught, we know we already have such a String, and can just return it as-is.
Diffstat (limited to 'Utility/FileSystemEncoding.hs')
-rw-r--r--Utility/FileSystemEncoding.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/Utility/FileSystemEncoding.hs b/Utility/FileSystemEncoding.hs
index 5a2fab0e4..2d9691d52 100644
--- a/Utility/FileSystemEncoding.hs
+++ b/Utility/FileSystemEncoding.hs
@@ -35,6 +35,8 @@ import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Lazy.UTF8 as L8
#endif
+import Utility.Exception
+
{- Sets a Handle to use the filesystem encoding. This causes data
- written or read from it to be encoded/decoded the same
- as ghc 7.4 does to filenames etc. This special encoding
@@ -70,14 +72,14 @@ withFilePath fp f = Encoding.getFileSystemEncoding
- effects.
-
- If the FilePath contains a value that is not legal in the filesystem
- - encoding, this may throw an exception. For example, "\226" is not valid
- - in the C locale, but is in utf locales.
+ - encoding, rather than thowing an exception, it will be returned as-is.
-}
{-# NOINLINE _encodeFilePath #-}
_encodeFilePath :: FilePath -> String
_encodeFilePath fp = unsafePerformIO $ do
enc <- Encoding.getFileSystemEncoding
- GHC.withCString enc fp $ GHC.peekCString Encoding.char8
+ GHC.withCString enc fp (GHC.peekCString Encoding.char8)
+ `catchNonAsync` (\_ -> return fp)
{- Encodes a FilePath into a Md5.Str, applying the filesystem encoding. -}
md5FilePath :: FilePath -> MD5.Str