git-annex/Backend/SHA1.hs

27 lines
597 B
Haskell
Raw Normal View History

2010-10-15 23:33:10 +00:00
{- git-annex "SHA1" backend
2010-10-10 19:27:49 +00:00
- -}
2010-10-15 23:33:10 +00:00
module Backend.SHA1 (backend) where
2010-10-10 19:27:49 +00:00
import Control.Monad.State
import Data.String.Utils
import System.Cmd.Utils
import System.IO
2010-10-16 20:20:49 +00:00
import qualified Backend.File
2010-10-18 06:06:27 +00:00
import TypeInternals
2010-10-10 19:27:49 +00:00
2010-10-14 07:50:28 +00:00
backend = Backend.File.backend {
2010-10-15 23:33:10 +00:00
name = "SHA1",
2010-10-10 19:27:49 +00:00
getKey = keyValue
}
2010-10-10 19:41:35 +00:00
-- checksum the file to get its key
2010-10-14 01:28:47 +00:00
keyValue :: FilePath -> Annex (Maybe Key)
keyValue file = 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)