smudge: Warn when encountering a pointer file that has other content appended to it

It will then proceed to add the file the same as if it were any other
file containing possibly annexable content. Usually the file is one that
was annexed before, so the new, probably corrupt content will also be added
to the annex. If the file was not annexed before, the content will be added
to git.

It's not possible for the smudge filter to throw an error here, because
git then just adds the file to git anyway.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2022-02-23 15:17:08 -04:00
parent 67245ae00f
commit 64ccb4734e
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 55 additions and 23 deletions

View file

@ -1,6 +1,6 @@
{- git-annex command
-
- Copyright 2015-2021 Joey Hess <id@joeyh.name>
- Copyright 2015-2022 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -105,7 +105,7 @@ clean file = do
then L.length b `seq` return ()
else liftIO $ hClose stdin
let emitpointer = liftIO . S.hPut stdout . formatPointer
clean' file (parseLinkTargetOrPointerLazy b)
clean' file (parseLinkTargetOrPointerLazy' b)
passthrough
discardreststdin
emitpointer
@ -115,7 +115,7 @@ clean file = do
-- Handles everything except the IO of the file content.
clean'
:: RawFilePath
-> Maybe Key
-> Either InvalidAppendedPointerFile (Maybe Key)
-- ^ If the content provided by git is an annex pointer,
-- this is the key it points to.
-> Annex ()
@ -135,19 +135,26 @@ clean' file mk passthrough discardreststdin emitpointer =
where
go = case mk of
Just k -> do
Right (Just k) -> do
addingExistingLink file k $ do
getMoveRaceRecovery k file
passthrough
Nothing -> inRepo (Git.Ref.fileRef file) >>= \case
Just fileref -> do
indexmeta <- catObjectMetaData fileref
oldkey <- case indexmeta of
Just (_, sz, _) -> catKey' fileref sz
Nothing -> return Nothing
go' indexmeta oldkey
Nothing -> passthrough
go' indexmeta oldkey = ifM (shouldAnnex file indexmeta oldkey)
Right Nothing -> notpointer
Left InvalidAppendedPointerFile -> do
toplevelWarning False $
"The file \"" ++ fromRawFilePath file ++ "\" looks like git-annex pointer file that has had other content appended to it"
notpointer
notpointer = inRepo (Git.Ref.fileRef file) >>= \case
Just fileref -> do
indexmeta <- catObjectMetaData fileref
oldkey <- case indexmeta of
Just (_, sz, _) -> catKey' fileref sz
Nothing -> return Nothing
notpointer' indexmeta oldkey
Nothing -> passthrough
notpointer' indexmeta oldkey = ifM (shouldAnnex file indexmeta oldkey)
( do
discardreststdin