stop using MissingH for MD5

Cryptonite is faster and allocates less, and I want to get rid of
MissingH use.

Note that the new dependency on memory is free; it's a dependency of
cryptonite.

This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
Joey Hess 2017-05-15 18:10:13 -04:00
parent 44baa7b306
commit 6dd806f1ad
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
11 changed files with 98 additions and 30 deletions

View file

@ -12,7 +12,6 @@ module Utility.FileSystemEncoding (
useFileSystemEncoding,
fileEncoding,
withFilePath,
md5FilePath,
decodeBS,
encodeBS,
decodeW8,
@ -27,7 +26,6 @@ import qualified GHC.IO.Encoding as Encoding
import Foreign.C
import System.IO
import System.IO.Unsafe
import qualified Data.Hash.MD5 as MD5
import Data.Word
import Data.Bits.Utils
import Data.List
@ -101,10 +99,6 @@ _encodeFilePath fp = unsafePerformIO $ do
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
md5FilePath = MD5.Str . _encodeFilePath
{- Decodes a ByteString into a FilePath, applying the filesystem encoding. -}
decodeBS :: L.ByteString -> FilePath
#ifndef mingw32_HOST_OS

View file

@ -1,8 +1,4 @@
{- Convenience wrapper around cryptohash/cryptonite.
-
- SHA3 hashes are currently only enabled when using cryptonite,
- because of https://github.com/vincenthz/hs-cryptohash/issues/36
-}
{- Convenience wrapper around cryptonite's hashing. -}
module Utility.Hash (
sha1,

View file

@ -25,6 +25,8 @@ import Utility.Path
import Utility.FileMode
import Utility.LockFile.LockStatus
import Utility.ThreadScheduler
import Utility.Hash
import Utility.FileSystemEncoding
import qualified Utility.LockFile.Posix as Posix
import System.IO
@ -33,7 +35,6 @@ import Data.Maybe
import Data.List
import Network.BSD
import System.FilePath
import Data.Hash.MD5
import Control.Applicative
import Prelude
@ -99,7 +100,9 @@ sideLockFile lockfile = do
f <- absPath lockfile
let base = intercalate "_" (splitDirectories (makeRelative "/" f))
let shortbase = reverse $ take 32 $ reverse base
let md5sum = if base == shortbase then "" else md5s (Str base)
let md5sum = if base == shortbase
then ""
else show (md5 (encodeBS base))
dir <- ifM (doesDirectoryExist "/dev/shm")
( return "/dev/shm"
, return "/tmp"

15
Utility/Tuple.hs Normal file
View file

@ -0,0 +1,15 @@
{- tuple utility functions
-
- Copyright 2017 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
fst3 :: (a,b,c) -> a
fst3 (a,b,c) = a
snd3 :: (a,b,c) -> b
snd3 (a,b,c) = b
thd3 :: (a,b,c) -> c
thd3 (a,b,c) = c