fix rekey/migrate bookkeeping in v6

After 220317df5a the test suite still
detected a problem; migrate of an unlocked file replaced it with a
pointer file rather than a file with the content.

This was a bookeeping problem; the worktree file was being copied to the object
file and the inode cache updated, but if that database write didn't get
flushed in time, later checks would think the content was not present.
Fixed by copying the object file to the worktree file instead, which
avoids needing to update the inode cache.

Also, only copy when there's a hard link to break, not always.

This commit was sponsored by Brock Spratlen on Patreon.
This commit is contained in:
Joey Hess 2018-10-16 17:18:21 -04:00
parent 220317df5a
commit 558520d27a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -87,17 +87,17 @@ linkKey file oldkey newkey = ifM (isJust <$> isAnnexLink file)
oldobj <- calcRepo (gitAnnexLocation oldkey) oldobj <- calcRepo (gitAnnexLocation oldkey)
isJust <$> linkOrCopy' (return True) newkey oldobj tmp Nothing isJust <$> linkOrCopy' (return True) newkey oldobj tmp Nothing
, do , do
{- The file being rekeyed is itself an unlocked file, so if {- The file being rekeyed is itself an unlocked file; if
- it's linked to the old key, that link must be broken. -} - it's hard linked to the old key, that link must be broken. -}
oldobj <- calcRepo (gitAnnexLocation oldkey) oldobj <- calcRepo (gitAnnexLocation oldkey)
v <- tryNonAsync $ modifyContent oldobj $ do v <- tryNonAsync $ do
replaceFile oldobj $ \tmp -> st <- liftIO $ getFileStatus file
unlessM (checkedCopyFile oldkey file tmp Nothing) $ when (linkCount st > 1) $ do
error "can't lock old key" freezeContent oldobj
freezeContent oldobj replaceFile file $ \tmp -> do
oldic <- withTSDelta (liftIO . genInodeCache oldobj) unlessM (checkedCopyFile oldkey oldobj tmp Nothing) $
whenM (isUnmodified oldkey oldobj) $ error "can't lock old key"
Database.Keys.addInodeCaches oldkey (catMaybes [oldic]) thawContent tmp
ic <- withTSDelta (liftIO . genInodeCache file) ic <- withTSDelta (liftIO . genInodeCache file)
case v of case v of
Left e -> do Left e -> do