direct: Fix a bug that could cause some files to be left in indirect mode.

It's possible for files in indirect mode to have a direct mode mapping
file. Probably from when they were in direct mode. In this case,
toDirectGen tried to copy the content from the direct mode file that the
mapping said had it. But, being in indirect mode, it didn't really have the
content. So it did nothing. This fix makes it always move the content from
.git/annex/objects/ when it's there.
This commit is contained in:
Joey Hess 2013-05-06 12:43:03 -04:00
parent c098d28e3c
commit 247b7e9e58
2 changed files with 21 additions and 18 deletions

View file

@ -182,25 +182,27 @@ toDirect k f = fromMaybe noop =<< toDirectGen k f
toDirectGen :: Key -> FilePath -> Annex (Maybe (Annex ())) toDirectGen :: Key -> FilePath -> Annex (Maybe (Annex ()))
toDirectGen k f = do toDirectGen k f = do
loc <- calcRepo $ gitAnnexLocation k loc <- calcRepo $ gitAnnexLocation k
absf <- liftIO $ absPath f ifM (liftIO $ doesFileExist loc)
locs <- filter (/= absf) <$> addAssociatedFile k f ( fromindirect loc
case locs of , fromdirect
[] -> ifM (liftIO $ doesFileExist loc) )
( return $ Just $ do where
{- Move content from annex to direct file. -} fromindirect loc = return $ Just $ do
thawContentDir loc {- Move content from annex to direct file. -}
updateInodeCache k loc thawContentDir loc
thawContent loc updateInodeCache k loc
replaceFile f $ liftIO . moveFile loc thawContent loc
, return Nothing replaceFile f $ liftIO . moveFile loc
) fromdirect = do
(loc':_) -> ifM (isNothing <$> getAnnexLinkTarget loc') {- Copy content from another direct file. -}
{- Another direct file has the content; copy it. -} absf <- liftIO $ absPath f
( return $ Just $ locs <- filterM (\loc -> isNothing <$> getAnnexLinkTarget loc) =<<
(filter (/= absf) <$> addAssociatedFile k f)
case locs of
(loc:_) -> return $ Just $
replaceFile f $ replaceFile f $
liftIO . void . copyFileExternal loc' liftIO . void . copyFileExternal loc
, return Nothing _ -> return Nothing
)
{- Removes a direct mode file, while retaining its content. -} {- Removes a direct mode file, while retaining its content. -}
removeDirect :: Key -> FilePath -> Annex () removeDirect :: Key -> FilePath -> Annex ()

1
debian/changelog vendored
View file

@ -9,6 +9,7 @@ git-annex (4.20130502) UNRELEASED; urgency=low
to link -lHSrts_thr to link -lHSrts_thr
* Avoid depending on regex-tdfa on mips, mipsel, and s390, where it fails * Avoid depending on regex-tdfa on mips, mipsel, and s390, where it fails
to build. to build.
* direct: Fix a bug that could cause some files to be left in indirect mode.
-- Joey Hess <joeyh@debian.org> Thu, 02 May 2013 20:39:19 -0400 -- Joey Hess <joeyh@debian.org> Thu, 02 May 2013 20:39:19 -0400