aboutsummaryrefslogtreecommitdiff
path: root/Annex/Content.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-09 15:25:14 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-09 15:27:29 -0400
commit7f00b7eaf0877e791194e7dfed5abefbb091ee86 (patch)
tree5639b58b816f524973bc8dd5252abac7e666d15d /Annex/Content.hs
parent61cab610d572cbfeb798f1ed09da4160b2cbba07 (diff)
link/copy pointer files to object content when it's added
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r--Annex/Content.hs20
1 files changed, 18 insertions, 2 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index 73cb6ab01..d3bf4f94f 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -72,6 +72,7 @@ import qualified Types.Backend
import qualified Backend
import Types.NumCopies
import Annex.UUID
+import qualified Database.AssociatedFiles as AssociatedFiles
{- Checks if a given key's content is currently present. -}
inAnnex :: Key -> Annex Bool
@@ -414,7 +415,10 @@ checkDiskSpace destination key alreadythere samefilesystem = ifM (Annex.getState
{- Moves a key's content into .git/annex/objects/
-
- - In direct mode, moves it to the associated file, or files.
+ - When a key has associated pointer files, the object is hard
+ - linked (or copied) to the files, and the object file is left thawed.
+
+ - In direct mode, moves the object file to the associated file, or files.
-
- What if the key there already has content? This could happen for
- various reasons; perhaps the same content is being annexed again.
@@ -442,7 +446,10 @@ moveAnnex key src = withObjectLoc key storeobject storedirect
( alreadyhave
, modifyContent dest $ do
liftIO $ moveFile src dest
- freezeContent dest
+ fs <- AssociatedFiles.getDb key
+ if null fs
+ then freezeContent dest
+ else mapM_ (populateAssociatedFile key dest) fs
)
storeindirect = storeobject =<< calcRepo (gitAnnexLocation key)
@@ -472,6 +479,15 @@ moveAnnex key src = withObjectLoc key storeobject storedirect
alreadyhave = liftIO $ removeFile src
+populateAssociatedFile :: Key -> FilePath -> FilePath -> Annex ()
+populateAssociatedFile k obj f = go =<< isPointerFile f
+ where
+ go (Just k') | k == k' = liftIO $ do
+ nukeFile f
+ unlessM (catchBoolIO $ createLinkOrCopy obj f) $
+ writeFile f (formatPointer k)
+ go _ = return ()
+
{- Hard links a file into .git/annex/objects/, falling back to a copy
- if necessary.
-