summaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-10 15:04:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-10 15:04:07 -0400
commitf4d2a05e86df464790fb183148717e7ac7f49cda (patch)
treef06c76bc6f89c23aaadd5633c4df31001290e55f /Annex.hs
parent80ce5f90db1de10a5fa42583efcb7390cf185662 (diff)
got annexing working
Diffstat (limited to 'Annex.hs')
-rw-r--r--Annex.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Annex.hs b/Annex.hs
new file mode 100644
index 000000000..7d89c882a
--- /dev/null
+++ b/Annex.hs
@@ -0,0 +1,36 @@
+{- git-annex
+ -}
+
+module Annex where
+
+import Backend
+import System.Posix.Files
+import System.Directory
+import GitRepo
+import Utility
+
+{- An annexed file's content is stored in .git/annex/. -}
+annexedFileLocation repo file = do
+ dir <- gitDir repo
+ return $ dir ++ "/annex/" ++ (gitRelative repo file)
+
+{- Annexes a file, storing it in a backend, and then moving it into
+ - the annex directory and setting up the symlink pointing to its
+ - content. -}
+annexFile :: [Backend] -> GitRepo -> FilePath -> IO ()
+annexFile backends repo file = do
+ alreadyannexed <- lookupBackend backends repo file
+ case (alreadyannexed) of
+ Just _ -> error $ "already annexed " ++ file
+ Nothing -> do
+ stored <- storeFile backends repo file
+ if (not stored)
+ then error $ "no backend could store " ++ file
+ else symlink
+ where
+ symlink = do
+ dest <- annexedFileLocation repo file
+ createDirectoryIfMissing True (parentDir dest)
+ renameFile file dest
+ createSymbolicLink dest file
+ gitAdd repo file