fix hard links when upgrading from direct mode

When upgrading a direct mode repo to v7 with adjusted unlocked branches,
fix a bug that prevented annex.thin from taking effect for the files in
working tree.

The hard links used to be ok, but commit 8e22114735 accidentially
broke them. It repopulates the worktree file, which is already a hard link,
and when it's creating the new file, the link count is already 2, and so it
doesn't make a hard link then.
This commit is contained in:
Joey Hess 2019-08-26 13:46:58 -04:00
parent 1e02360283
commit 5877a15d7b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 48 additions and 35 deletions

View file

@ -75,10 +75,11 @@ ifAnnexed file yes no = maybe no yes =<< lookupFile file
- when initializing/upgrading a v6+ mode repository.
-
- Also, the content for the unlocked file may already be present as
- an annex object. If so, make the unlocked file use that content.
- an annex object. If so, make the unlocked file use that content
- when replacefiles is True.
-}
scanUnlockedFiles :: Annex ()
scanUnlockedFiles = whenM (inRepo Git.Ref.headExists) $ do
scanUnlockedFiles :: Bool -> Annex ()
scanUnlockedFiles replacefiles = whenM (inRepo Git.Ref.headExists) $ do
showSideAction "scanning for unlocked files"
Database.Keys.runWriter $
liftIO . Database.Keys.SQL.dropAllAssociatedFiles
@ -97,7 +98,7 @@ scanUnlockedFiles = whenM (inRepo Git.Ref.headExists) $ do
let tf = Git.LsTree.file i
Database.Keys.runWriter $
liftIO . Database.Keys.SQL.addAssociatedFileFast (toIKey k) tf
whenM (inAnnex k) $ do
whenM (pure replacefiles <&&> inAnnex k) $ do
f <- fromRepo $ fromTopFilePath tf
destmode <- liftIO $ catchMaybeIO $ fileMode <$> getFileStatus f
ic <- replaceFile f $ \tmp ->