improve handling of receiving object in direct mode when associated files are modified

Before, if a direct mode repo had one or more associated files that
were modifed, moving the object into it would overwrite the associated
files with the pristine object.

Now, modified associated files are left unchanged. To ensure that,
when an object is moved into a direct mode repo, it's not thrown away,
it gets stored in indirect mode.
This commit is contained in:
Joey Hess 2013-05-17 16:25:18 -04:00
parent 7bcfa88e6b
commit 1b616c5d37

View file

@ -245,25 +245,40 @@ moveAnnex :: Key -> FilePath -> Annex ()
moveAnnex key src = withObjectLoc key storeobject storedirect moveAnnex key src = withObjectLoc key storeobject storedirect
where where
storeobject dest = ifM (liftIO $ doesFileExist dest) storeobject dest = ifM (liftIO $ doesFileExist dest)
( liftIO $ removeFile src ( alreadyhave
, do , do
createContentDir dest createContentDir dest
liftIO $ moveFile src dest liftIO $ moveFile src dest
freezeContent dest freezeContent dest
freezeContentDir dest freezeContentDir dest
) )
storedirect fs = storedirect' =<< filterM validsymlink fs storeindirect = storeobject =<< calcRepo (gitAnnexLocation key)
validsymlink f = (==) (Just key) <$> isAnnexLink f
storedirect' [] = storeobject =<< calcRepo (gitAnnexLocation key) {- In direct mode, the associated file's content may be locally
storedirect' (f:fs) = do - modified. In that case, it's preserved. However, the content
- we're moving into the annex may be the only extant copy, so
- it's important we not lose it. So, when the key's content
- cannot be moved to any associated file, it's stored in indirect
- mode.
-}
storedirect = storedirect' storeindirect
storedirect' fallback [] = fallback
storedirect' fallback (f:fs) = do
thawContentDir =<< calcRepo (gitAnnexLocation key) thawContentDir =<< calcRepo (gitAnnexLocation key)
updateInodeCache key src
thawContent src thawContent src
replaceFile f $ liftIO . moveFile src v <- isAnnexLink f
{- Copy to any other locations. -} if (Just key == v)
forM_ fs $ then do
addContentWhenNotPresent key f updateInodeCache key src
replaceFile f $ liftIO . moveFile src
forM_ fs $
addContentWhenNotPresent key f
else ifM (goodContent key f)
( storedirect' alreadyhave fs
, storedirect' fallback fs
)
alreadyhave = liftIO $ removeFile src
{- Runs an action to transfer an object's content. {- Runs an action to transfer an object's content.
- -