summaryrefslogtreecommitdiff
path: root/Annex/Content/Direct.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-17 15:59:37 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-17 15:59:37 -0400
commit4e74c0d7f33a66eb524ef020ef4401fa322db34c (patch)
treed0a239d6022339b3cb5afeced2d3f859aa4d02d3 /Annex/Content/Direct.hs
parent963f2c5726ce0fe899038733d4318a234d355268 (diff)
test suite passes in direct mode
This fixes a bug with git annex add in direct mode. If some files already existed in the tree pointing at the same key as a file that was just added, and their content was not present, add neglected to copy the content to those files. I also changed the behavior of moveAnnex slightly: When content is moved into the annex in direct mode, it does not overwrite any content already present in direct mode files. That content may be modified after all.
Diffstat (limited to 'Annex/Content/Direct.hs')
-rw-r--r--Annex/Content/Direct.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs
index b885b5e5b..49d317258 100644
--- a/Annex/Content/Direct.hs
+++ b/Annex/Content/Direct.hs
@@ -23,6 +23,7 @@ module Annex.Content.Direct (
toInodeCache,
inodesChanged,
createInodeSentinalFile,
+ addContentWhenNotPresent,
) where
import Common.Annex
@@ -32,6 +33,9 @@ import qualified Git
import Utility.Tmp
import Logs.Location
import Utility.InodeCache
+import Utility.CopyFile
+import Annex.ReplaceFile
+import Annex.Link
{- Absolute FilePaths of Files in the tree that are associated with a key. -}
associatedFiles :: Key -> Annex [FilePath]
@@ -180,6 +184,16 @@ elemInodeCaches c (l:ls) = ifM (compareInodeCaches c l)
compareInodeCachesWith :: Annex InodeComparisonType
compareInodeCachesWith = ifM inodesChanged ( return Weakly, return Strongly )
+{- Copies the contentfile to the associated file, if the associated
+ - file has not content. If the associated file does have content,
+ - even if the content differs, it's left unchanged. -}
+addContentWhenNotPresent :: Key -> FilePath -> FilePath -> Annex ()
+addContentWhenNotPresent key contentfile associatedfile = do
+ v <- isAnnexLink associatedfile
+ when (Just key == v) $
+ replaceFile associatedfile $
+ liftIO . void . copyFileExternal contentfile
+
{- Some filesystems get new inodes each time they are mounted.
- In order to work on such a filesystem, a sentinal file is used to detect
- when the inodes have changed.