git-annex/Backend/SHA1.hs

35 lines
758 B
Haskell
Raw Normal View History

2010-10-15 19:33:10 -04:00
{- git-annex "SHA1" backend
2010-10-27 16:53:54 -04:00
-
- Copyright 2010 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
2010-10-10 15:27:49 -04:00
2010-10-15 19:33:10 -04:00
module Backend.SHA1 (backend) where
2010-10-10 15:27:49 -04:00
import Control.Monad.State
import Data.String.Utils
import System.Cmd.Utils
import System.IO
2010-10-16 16:20:49 -04:00
import qualified Backend.File
2010-10-18 02:06:27 -04:00
import TypeInternals
2010-11-01 22:50:53 -04:00
import Core
2010-10-10 15:27:49 -04:00
2010-10-31 16:00:32 -04:00
backend :: Backend
2010-10-14 03:50:28 -04:00
backend = Backend.File.backend {
2010-10-15 19:33:10 -04:00
name = "SHA1",
2010-10-10 15:27:49 -04:00
getKey = keyValue
}
2010-10-10 15:41:35 -04:00
-- checksum the file to get its key
2010-10-13 21:28:47 -04:00
keyValue :: FilePath -> Annex (Maybe Key)
2010-11-01 22:50:53 -04:00
keyValue file = do
2010-11-02 02:24:19 -04:00
showNote "checksum..."
2010-11-01 22:50:53 -04:00
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)