From 558520d27a0a9e47c7daa9c6e267a884f3b1e62e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 16 Oct 2018 17:18:21 -0400 Subject: [PATCH] fix rekey/migrate bookkeeping in v6 After 220317df5a115eb815a0112073f35d7e107c65d7 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. --- Command/ReKey.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Command/ReKey.hs b/Command/ReKey.hs index cd67ed2fd0..ef97d2459e 100644 --- a/Command/ReKey.hs +++ b/Command/ReKey.hs @@ -87,17 +87,17 @@ linkKey file oldkey newkey = ifM (isJust <$> isAnnexLink file) oldobj <- calcRepo (gitAnnexLocation oldkey) isJust <$> linkOrCopy' (return True) newkey oldobj tmp Nothing , do - {- The file being rekeyed is itself an unlocked file, so if - - it's linked to the old key, that link must be broken. -} + {- The file being rekeyed is itself an unlocked file; if + - it's hard linked to the old key, that link must be broken. -} oldobj <- calcRepo (gitAnnexLocation oldkey) - v <- tryNonAsync $ modifyContent oldobj $ do - replaceFile oldobj $ \tmp -> - unlessM (checkedCopyFile oldkey file tmp Nothing) $ - error "can't lock old key" - freezeContent oldobj - oldic <- withTSDelta (liftIO . genInodeCache oldobj) - whenM (isUnmodified oldkey oldobj) $ - Database.Keys.addInodeCaches oldkey (catMaybes [oldic]) + v <- tryNonAsync $ do + st <- liftIO $ getFileStatus file + when (linkCount st > 1) $ do + freezeContent oldobj + replaceFile file $ \tmp -> do + unlessM (checkedCopyFile oldkey oldobj tmp Nothing) $ + error "can't lock old key" + thawContent tmp ic <- withTSDelta (liftIO . genInodeCache file) case v of Left e -> do