From 6242b35c33eb3333edef17f4026dc84ebd550d35 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 9 Dec 2021 15:25:59 -0400 Subject: [PATCH] fix error message Was "failed to generate a key" when key generation did not fail (it never does anymore) but the actual problem was it failed to stat the source file, perhaps due to it being deleted while the key was being generated. A user reported this, in a comment I followed up on in 262400fe0417f447ab48ab6be799c43d3222a233, although I don't know what they did to trigger the error message. --- Annex/Ingest.hs | 25 ++++++++++++------------- Annex/MetaData.hs | 15 +++++++++------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Annex/Ingest.hs b/Annex/Ingest.hs index 4b4290fded..ef34b3476b 100644 --- a/Annex/Ingest.hs +++ b/Annex/Ingest.hs @@ -184,18 +184,17 @@ ingest' preferredbackend meterupdate (Just (LockedDown cfg source)) mk restage = ms <- liftIO $ catchMaybeIO $ R.getFileStatus src mcache <- maybe (pure Nothing) (liftIO . toInodeCache delta src) ms case (mcache, inodeCache source) of - (_, Nothing) -> go k mcache ms - (Just newc, Just c) | compareStrong c newc -> go k mcache ms + (_, Nothing) -> go k mcache + (Just newc, Just c) | compareStrong c newc -> go k mcache _ -> failure "changed while it was being added" where - go key mcache (Just s) - | lockingFile cfg = golocked key mcache s - | otherwise = gounlocked key mcache s - go _ _ Nothing = failure "failed to generate a key" + go key mcache + | lockingFile cfg = golocked key mcache + | otherwise = gounlocked key mcache - golocked key mcache s = + golocked key mcache = tryNonAsync (moveAnnex key naf (contentLocation source)) >>= \case - Right True -> success key mcache s + Right True -> success key mcache Right False -> giveup "failed to add content to annex" Left e -> restoreFile (keyFilename source) key e @@ -205,7 +204,7 @@ ingest' preferredbackend meterupdate (Just (LockedDown cfg source)) mk restage = -- file, so provide it nothing. naf = AssociatedFile Nothing - gounlocked key (Just cache) s = do + gounlocked key (Just cache) = do -- Remove temp directory hard link first because -- linkToAnnex falls back to copying if a file -- already has a hard link. @@ -215,11 +214,11 @@ ingest' preferredbackend meterupdate (Just (LockedDown cfg source)) mk restage = LinkAnnexFailed -> failure "failed to link to annex" lar -> do finishIngestUnlocked' key source restage (Just lar) - success key (Just cache) s - gounlocked _ _ _ = failure "failed statting file" + success key (Just cache) + gounlocked _ _ = failure "failed statting file" - success k mcache s = do - genMetaData k (keyFilename source) s + success k mcache = do + genMetaData k (keyFilename source) (fmap inodeCacheToMtime mcache) return (Just k, mcache) failure msg = do diff --git a/Annex/MetaData.hs b/Annex/MetaData.hs index a21cdd601f..4b57b1663a 100644 --- a/Annex/MetaData.hs +++ b/Annex/MetaData.hs @@ -37,8 +37,8 @@ import Data.Time.Clock.POSIX - - Also, can generate new metadata, if configured to do so. -} -genMetaData :: Key -> RawFilePath -> FileStatus -> Annex () -genMetaData key file status = do +genMetaData :: Key -> RawFilePath -> Maybe POSIXTime -> Annex () +genMetaData key file mmtime = do catKeyFileHEAD file >>= \case Nothing -> noop Just oldkey -> @@ -47,11 +47,14 @@ genMetaData key file status = do -- preserve any metadata already on key. whenM (copyMetaData oldkey key <&&> (not <$> onlydatemeta oldkey)) $ warncopied - whenM (annexGenMetaData <$> Annex.getGitConfig) $ do - old <- getCurrentMetaData key - addMetaData key (dateMetaData mtime old) + whenM (annexGenMetaData <$> Annex.getGitConfig) $ + case mmtime of + Just mtime -> do + old <- getCurrentMetaData key + addMetaData key $ + dateMetaData (posixSecondsToUTCTime mtime) old + Nothing -> noop where - mtime = posixSecondsToUTCTime $ realToFrac $ modificationTime status warncopied = warning $ "Copied metadata from old version of " ++ fromRawFilePath file ++ " to new version. " ++ "If you don't want this copied metadata, run: git annex metadata --remove-all " ++ fromRawFilePath file