blob: 76869b071d70ff7cf52f9d61601335dd7e6bf954 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
{- git-annex "SHA1" backend
-
- Copyright 2010 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Backend.SHA1 (backend) where
import Control.Monad.State
import Data.String.Utils
import System.Cmd.Utils
import System.IO
import qualified Backend.File
import TypeInternals
import Core
backend :: Backend
backend = Backend.File.backend {
name = "SHA1",
getKey = keyValue
}
-- checksum the file to get its key
keyValue :: FilePath -> Annex (Maybe Key)
keyValue file = do
showNote "checksum"
liftIO $ pOpen ReadFromPipe "sha1sum" [file] $ \h -> do
line <- hGetLine h
let bits = split " " line
if (null bits)
then error "sha1sum parse error"
else return $ Just $ Key ((name backend), bits !! 0)
|