aboutsummaryrefslogtreecommitdiff
path: root/Annex/Ingest.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-22 16:22:28 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-22 16:22:28 -0400
commit08f1265886b5cd8646e73f7ed0013b94d34b5f14 (patch)
tree55d6170dafbb39ceda0a73229adc2a5a50722eba /Annex/Ingest.hs
parent56d1ad16c61d9e5abe1c123b3f791c9e5f641bd8 (diff)
populate unlocked files with newly available content when ingesting
This can happen when ingesting a new file in either locked or unlocked mode, when some unlocked files in the repo use the same key, and the content was not locally available before.
Diffstat (limited to 'Annex/Ingest.hs')
-rw-r--r--Annex/Ingest.hs29
1 files changed, 25 insertions, 4 deletions
diff --git a/Annex/Ingest.hs b/Annex/Ingest.hs
index 707f71eff..7f38e9beb 100644
--- a/Annex/Ingest.hs
+++ b/Annex/Ingest.hs
@@ -12,6 +12,7 @@ module Annex.Ingest (
lockDown,
ingest,
finishIngestDirect,
+ finishIngestUnlocked,
addLink,
makeLink,
restoreFile,
@@ -28,6 +29,7 @@ import Annex.Link
import Annex.MetaData
import qualified Annex
import qualified Annex.Queue
+import qualified Database.Keys
import Config
import Utility.InodeCache
import Annex.ReplaceFile
@@ -59,9 +61,8 @@ data LockedDown = LockedDown
- against some changes, like deletion or overwrite of the file, and
- allows lsof checks to be done more efficiently when adding a lot of files.
-
- - If the file is to be locked, lockingfile is True. Then the write
- - bit is removed from the file as part of lock down to guard against
- - further writes.
+ - If lockingfile is True, the file is going to be added in locked mode.
+ - So, its write bit is removed as part of the lock down.
-
- Lockdown can fail if a file gets deleted, and Nothing will be returned.
-}
@@ -134,13 +135,20 @@ ingest (Just (LockedDown lockingfile source)) = withTSDelta $ \delta -> do
catchNonAsync (moveAnnex key $ contentLocation source)
(restoreFile (keyFilename source) key)
liftIO $ nukeFile $ keyFilename source
+ populateAssociatedFiles key source
success key mcache s
gounlocked key (Just cache) s = do
+ -- Remove temp directory hard link first because
+ -- linkAnnex falls back to copying if a file
+ -- already has a hard link.
+ cleanCruft source
r <- linkAnnex key (keyFilename source) (Just cache)
case r of
LinkAnnexFailed -> failure "failed to link to annex"
- _ -> success key (Just cache) s
+ _ -> do
+ finishIngestUnlocked key source
+ success key (Just cache) s
gounlocked _ _ _ = failure "failed statting file"
godirect key (Just cache) s = do
@@ -168,6 +176,19 @@ finishIngestDirect key source = do
forM_ otherfs $
addContentWhenNotPresent key (keyFilename source)
+finishIngestUnlocked :: Key -> KeySource -> Annex ()
+finishIngestUnlocked key source = do
+ Database.Keys.addAssociatedFile key (keyFilename source)
+ populateAssociatedFiles key source
+
+{- Copy to any other locations using the same key. -}
+populateAssociatedFiles :: Key -> KeySource -> Annex ()
+populateAssociatedFiles key source = do
+ otherfs <- filter (/= keyFilename source) <$> Database.Keys.getAssociatedFiles key
+ obj <- calcRepo (gitAnnexLocation key)
+ forM_ otherfs $
+ populatePointerFile key obj
+
cleanCruft :: KeySource -> Annex ()
cleanCruft source = when (contentLocation source /= keyFilename source) $
liftIO $ nukeFile $ contentLocation source