git-annex/UUID.hs

40 lines
865 B
Haskell
Raw Normal View History

2010-10-12 17:10:07 +00:00
{- git-annex uuids
-
- Each git repository used by git-annex has an annex.uuid setting that
- uniquely identifies that repository.
-
-}
module UUID (
getUUID,
prepUUID,
genUUID
) where
import System.Cmd.Utils
import System.IO
import GitRepo
configkey="annex.uuid"
{- Generates a UUID. There is a library for this, but it's not packaged,
- so use the command line tool. -}
genUUID :: IO String
genUUID = do
pOpen ReadFromPipe "uuid" ["-m"] $ \h -> hGetLine h
2010-10-12 17:12:47 +00:00
{- Looks up a repo's UUID -}
2010-10-12 17:10:07 +00:00
getUUID :: GitRepo -> String
getUUID repo = gitConfig repo "annex.uuid" ""
{- Make sure that the repo has an annex.uuid setting. -}
2010-10-12 17:12:47 +00:00
prepUUID :: GitRepo -> IO GitRepo
2010-10-12 17:10:07 +00:00
prepUUID repo =
if ("" == getUUID repo)
then do
uuid <- genUUID
gitRun repo ["config", configkey, uuid]
2010-10-12 19:44:54 +00:00
-- return new repo with updated config
gitConfigRead repo
2010-10-12 17:12:47 +00:00
else return repo