From 4e74c0d7f33a66eb524ef020ef4401fa322db34c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 17 May 2013 15:59:37 -0400 Subject: 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. --- Annex/Content/Direct.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Annex/Content/Direct.hs') 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. -- cgit v1.2.3