summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-07 14:46:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-07 15:59:16 -0400
commit63a292324d20832b68c92f784828e55e644481cc (patch)
treef49c7077caf738cd285681421f9c9baa03068c99 /Annex
parentb08f7c428b4bc9eabd95596d08594ddd1057a0bf (diff)
add a UUID type
Should have done this a long time ago.
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Ssh.hs5
-rw-r--r--Annex/UUID.hs17
2 files changed, 12 insertions, 10 deletions
diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs
index 851c7c06b..f8cd5d9bc 100644
--- a/Annex/Ssh.hs
+++ b/Annex/Ssh.hs
@@ -45,9 +45,8 @@ git_annex_shell r command params
sshcmd uuid = unwords $
shellcmd : (map shellEscape $ toCommand shellopts) ++
uuidcheck uuid
- uuidcheck uuid
- | null uuid = []
- | otherwise = ["--uuid", uuid]
+ uuidcheck NoUUID = []
+ uuidcheck (UUID u) = ["--uuid", u]
{- Uses a supplied function (such as boolSystem) to run a git-annex-shell
- command on a remote.
diff --git a/Annex/UUID.hs b/Annex/UUID.hs
index 39e296e5b..90189bc47 100644
--- a/Annex/UUID.hs
+++ b/Annex/UUID.hs
@@ -30,7 +30,7 @@ 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 UUID
-genUUID = pOpen ReadFromPipe command params hGetLine
+genUUID = pOpen ReadFromPipe command params $ liftM read . hGetLine
where
command = SysConfig.uuid
params = if command == "uuid"
@@ -50,20 +50,23 @@ getRepoUUID r = do
let c = cached g
let u = getUncachedUUID r
- if c /= u && u /= ""
+ if c /= u && u /= NoUUID
then do
updatecache g u
return u
else return c
where
- cached g = Git.configGet g cachekey ""
- updatecache g u = when (g /= r) $ setConfig cachekey u
+ cached g = read $ Git.configGet g cachekey ""
+ updatecache g u = when (g /= r) $ storeUUID cachekey u
cachekey = "remote." ++ fromMaybe "" (Git.repoRemoteName r) ++ ".annex-uuid"
getUncachedUUID :: Git.Repo -> UUID
-getUncachedUUID r = Git.configGet r configkey ""
+getUncachedUUID r = read $ Git.configGet r configkey ""
{- Make sure that the repo has an annex.uuid setting. -}
prepUUID :: Annex ()
-prepUUID = whenM (null <$> getUUID) $
- setConfig configkey =<< liftIO genUUID
+prepUUID = whenM ((==) NoUUID <$> getUUID) $
+ storeUUID configkey =<< liftIO genUUID
+
+storeUUID :: String -> UUID -> Annex ()
+storeUUID configfield uuid = setConfig configfield (show uuid)