perhaps more clear type
This commit is contained in:
parent
10d9315b59
commit
f9d44cccd9
2 changed files with 6 additions and 6 deletions
|
@ -218,12 +218,12 @@ hashDirMixed :: Hasher
|
||||||
hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir
|
hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir
|
||||||
where
|
where
|
||||||
dir = take 4 $ display_32bits_as_dir =<< [a,b,c,d]
|
dir = take 4 $ display_32bits_as_dir =<< [a,b,c,d]
|
||||||
ABCD (a,b,c,d) = md5 $ Str $ encodeFilePath $ show k
|
ABCD (a,b,c,d) = md5 $ encodeFilePath $ show k
|
||||||
|
|
||||||
hashDirLower :: Hasher
|
hashDirLower :: Hasher
|
||||||
hashDirLower k = addTrailingPathSeparator $ take 3 dir </> drop 3 dir
|
hashDirLower k = addTrailingPathSeparator $ take 3 dir </> drop 3 dir
|
||||||
where
|
where
|
||||||
dir = take 6 $ md5s $ Str $ encodeFilePath $ show k
|
dir = take 6 $ md5s $ encodeFilePath $ show k
|
||||||
|
|
||||||
{- modified version of display_32bits_as_hex from Data.Hash.MD5
|
{- modified version of display_32bits_as_hex from Data.Hash.MD5
|
||||||
- Copyright (C) 2001 Ian Lynagh
|
- Copyright (C) 2001 Ian Lynagh
|
||||||
|
|
|
@ -12,6 +12,7 @@ import qualified GHC.IO.Encoding as Encoding
|
||||||
import Foreign.C
|
import Foreign.C
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.IO.Unsafe
|
import System.IO.Unsafe
|
||||||
|
import qualified Data.Hash.MD5 as MD5
|
||||||
|
|
||||||
{- Sets a Handle to use the filesystem encoding. This causes data
|
{- Sets a Handle to use the filesystem encoding. This causes data
|
||||||
- written or read from it to be encoded/decoded the same
|
- written or read from it to be encoded/decoded the same
|
||||||
|
@ -28,8 +29,7 @@ withFilePath :: FilePath -> (CString -> IO a) -> IO a
|
||||||
withFilePath fp f = Encoding.getFileSystemEncoding
|
withFilePath fp f = Encoding.getFileSystemEncoding
|
||||||
>>= \enc -> GHC.withCString enc fp f
|
>>= \enc -> GHC.withCString enc fp f
|
||||||
|
|
||||||
{- Encodes a FilePath into a String of encoded bytes, applying the
|
{- Encodes a FilePath into a Str, applying the filesystem encoding.
|
||||||
- filesystem encoding.
|
|
||||||
-
|
-
|
||||||
- This use of unsafePerformIO is belived to be safe; GHC's interface
|
- This use of unsafePerformIO is belived to be safe; GHC's interface
|
||||||
- only allows doing this conversion with CStrings, and the CString buffer
|
- only allows doing this conversion with CStrings, and the CString buffer
|
||||||
|
@ -37,7 +37,7 @@ withFilePath fp f = Encoding.getFileSystemEncoding
|
||||||
- effects.
|
- effects.
|
||||||
-}
|
-}
|
||||||
{-# NOINLINE encodeFilePath #-}
|
{-# NOINLINE encodeFilePath #-}
|
||||||
encodeFilePath :: FilePath -> String
|
encodeFilePath :: FilePath -> MD5.Str
|
||||||
encodeFilePath fp = unsafePerformIO $ do
|
encodeFilePath fp = MD5.Str $ unsafePerformIO $ do
|
||||||
enc <- Encoding.getFileSystemEncoding
|
enc <- Encoding.getFileSystemEncoding
|
||||||
GHC.withCString enc fp $ GHC.peekCString Encoding.char8
|
GHC.withCString enc fp $ GHC.peekCString Encoding.char8
|
||||||
|
|
Loading…
Reference in a new issue