avoid interrupted push leaving remote without a manifest

Added a backup manifest key, which is used if the main manifest key is
not present. When uploading a new Manifest, it makes sure that it never
drops one key except when the other key is present.

It's entirely possible for the two manifest keys to get out of sync, due
to races. The main one wins when it's present, it is possible for the
main one being dropped to expose the backup one, which has a different
push recorded.
This commit is contained in:
Joey Hess 2024-05-20 15:41:09 -04:00
parent 594ca2fd3a
commit 3a38520aac
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 67 additions and 67 deletions

View file

@ -84,9 +84,10 @@ genGitBundleKey remoteuuid file meterupdate = do
, keySize = Just filesize
}
genManifestKey :: UUID -> Key
genManifestKey u = mkKey $ \kd -> kd
{ keyName = S.toShort (fromUUID u)
genManifestKey :: UUID -> Maybe S.ShortByteString -> Key
genManifestKey u extension = mkKey $ \kd -> kd
{ keyName = S.toShort (fromUUID u) <>
maybe mempty ("." <>) extension
, keyVariety = GitManifestKey
}
@ -99,7 +100,14 @@ isGitRemoteAnnexKey u k =
-- Remove the checksum that comes after the UUID.
let b' = B8.dropWhileEnd (/= '-') b
in B8.take (B8.length b' - 1) b'
GitManifestKey -> sameuuid id
GitManifestKey -> sameuuid $ \b ->
-- Remove an optional extension after the UUID.
-- (A UUID never contains '.')
if '.' `B8.elem` b
then
let b' = B8.dropWhileEnd (/= '.') b
in B8.take (B8.length b' - 1) b'
else b
_ -> False
where
sameuuid f = fromUUID u == f (S.fromShort (fromKey keyName k))