summaryrefslogtreecommitdiff
path: root/Backend/SHA.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Backend/SHA.hs')
-rw-r--r--Backend/SHA.hs83
1 files changed, 41 insertions, 42 deletions
diff --git a/Backend/SHA.hs b/Backend/SHA.hs
index bfb94df99..ef0e92d20 100644
--- a/Backend/SHA.hs
+++ b/Backend/SHA.hs
@@ -57,24 +57,23 @@ shaN shasize file filesize = do
Left sha -> liftIO $ sha <$> L.readFile file
Right command -> liftIO $ parse command . lines <$>
readsha command (toCommand [File file])
- where
- parse command [] = bad command
- parse command (l:_)
- | null sha = bad command
- | otherwise = sha
- where
- sha = fst $ separate (== ' ') l
- bad command = error $ command ++ " parse error"
- {- sha commands output the filename, so need to set fileEncoding -}
- readsha command args =
- withHandle StdoutHandle createProcessSuccess p $ \h -> do
- fileEncoding h
- output <- hGetContentsStrict h
- hClose h
- return output
- where
- p = (proc command args)
- { std_out = CreatePipe }
+ where
+ parse command [] = bad command
+ parse command (l:_)
+ | null sha = bad command
+ | otherwise = sha
+ where
+ sha = fst $ separate (== ' ') l
+ bad command = error $ command ++ " parse error"
+ {- sha commands output the filename, so need to set fileEncoding -}
+ readsha command args =
+ withHandle StdoutHandle createProcessSuccess p $ \h -> do
+ fileEncoding h
+ output <- hGetContentsStrict h
+ hClose h
+ return output
+ where
+ p = (proc command args) { std_out = CreatePipe }
shaCommand :: SHASize -> Integer -> Either (L.ByteString -> String) String
shaCommand shasize filesize
@@ -84,14 +83,14 @@ shaCommand shasize filesize
| shasize == 384 = use SysConfig.sha384 sha384
| shasize == 512 = use SysConfig.sha512 sha512
| otherwise = error $ "bad sha size " ++ show shasize
- where
- use Nothing sha = Left $ showDigest . sha
- use (Just c) sha
- -- use builtin, but slower sha for small files
- -- benchmarking indicates it's faster up to
- -- and slightly beyond 50 kb files
- | filesize < 51200 = use Nothing sha
- | otherwise = Right c
+ where
+ use Nothing sha = Left $ showDigest . sha
+ use (Just c) sha
+ {- use builtin, but slower sha for small files
+ - benchmarking indicates it's faster up to
+ - and slightly beyond 50 kb files -}
+ | filesize < 51200 = use Nothing sha
+ | otherwise = Right c
{- A key is a checksum of its contents. -}
keyValue :: SHASize -> KeySource -> Annex (Maybe Key)
@@ -109,23 +108,23 @@ keyValue shasize source = do
{- Extension preserving keys. -}
keyValueE :: SHASize -> KeySource -> Annex (Maybe Key)
keyValueE size source = keyValue size source >>= maybe (return Nothing) addE
- where
- addE k = return $ Just $ k
- { keyName = keyName k ++ selectExtension (keyFilename source)
- , keyBackendName = shaNameE size
- }
+ where
+ addE k = return $ Just $ k
+ { keyName = keyName k ++ selectExtension (keyFilename source)
+ , keyBackendName = shaNameE size
+ }
selectExtension :: FilePath -> String
selectExtension f
| null es = ""
| otherwise = join "." ("":es)
- where
- es = filter (not . null) $ reverse $
- take 2 $ takeWhile shortenough $
- reverse $ split "." $ takeExtensions f
- shortenough e
- | '\n' `elem` e = False -- newline in extension?!
- | otherwise = length e <= 4 -- long enough for "jpeg"
+ where
+ es = filter (not . null) $ reverse $
+ take 2 $ takeWhile shortenough $
+ reverse $ split "." $ takeExtensions f
+ shortenough e
+ | '\n' `elem` e = False -- newline in extension?!
+ | otherwise = length e <= 4 -- long enough for "jpeg"
{- A key's checksum is checked during fsck. -}
checkKeyChecksum :: SHASize -> Key -> FilePath -> Annex Bool
@@ -137,7 +136,7 @@ checkKeyChecksum size key file = do
let filesize = fromIntegral $ fileSize stat
check <$> shaN size file filesize
_ -> return True
- where
- check s
- | s == dropExtensions (keyName key) = True
- | otherwise = False
+ where
+ check s
+ | s == dropExtensions (keyName key) = True
+ | otherwise = False