summaryrefslogtreecommitdiff
path: root/UUID.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-12 13:10:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-12 13:10:07 -0400
commitdc1d5e68317b85043c8c30a82f53f78b0a9a9f51 (patch)
treef276c940a74ea8888e746e61ddb891cf280a2d29 /UUID.hs
parentea5d7fe07a5c40349e66848fc9cd06a9f748b724 (diff)
update
Diffstat (limited to 'UUID.hs')
-rw-r--r--UUID.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/UUID.hs b/UUID.hs
new file mode 100644
index 000000000..a0e078482
--- /dev/null
+++ b/UUID.hs
@@ -0,0 +1,36 @@
+{- 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
+
+getUUID :: GitRepo -> String
+getUUID repo = gitConfig repo "annex.uuid" ""
+
+{- Make sure that the repo has an annex.uuid setting. -}
+prepUUID :: GitRepo -> IO ()
+prepUUID repo =
+ if ("" == getUUID repo)
+ then do
+ uuid <- genUUID
+ gitRun repo ["config", configkey, uuid]
+ else return ()