From 5f4ad2a5dedb67ebcba9ae16089d6b4bda6bb115 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 21 May 2024 09:51:19 -0400 Subject: [PATCH] refactor --- Backend/GitRemoteAnnex.hs | 13 ++++++++++--- CmdLine/GitRemoteAnnex.hs | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Backend/GitRemoteAnnex.hs b/Backend/GitRemoteAnnex.hs index 13c6b2820f..f7cb46a06b 100644 --- a/Backend/GitRemoteAnnex.hs +++ b/Backend/GitRemoteAnnex.hs @@ -14,6 +14,7 @@ module Backend.GitRemoteAnnex ( backends, genGitBundleKey, genManifestKey, + genBackupManifestKey, isGitRemoteAnnexKey, ) where @@ -84,10 +85,16 @@ genGitBundleKey remoteuuid file meterupdate = do , keySize = Just filesize } -genManifestKey :: UUID -> Maybe S.ShortByteString -> Key -genManifestKey u extension = mkKey $ \kd -> kd +genManifestKey :: UUID -> Key +genManifestKey = genManifestKey' Nothing + +genBackupManifestKey :: UUID -> Key +genBackupManifestKey = genManifestKey' (Just ".bak") + +genManifestKey' :: Maybe S.ShortByteString -> UUID -> Key +genManifestKey' extension u = mkKey $ \kd -> kd { keyName = S.toShort (fromUUID u) <> - maybe mempty ("." <>) extension + fromMaybe mempty extension , keyVariety = GitManifestKey } diff --git a/CmdLine/GitRemoteAnnex.hs b/CmdLine/GitRemoteAnnex.hs index 4ec8b9dc03..61d41581e3 100644 --- a/CmdLine/GitRemoteAnnex.hs +++ b/CmdLine/GitRemoteAnnex.hs @@ -587,8 +587,8 @@ downloadManifestOrFail rmt = downloadManifest :: Remote -> Annex (Maybe Manifest) downloadManifest rmt = get mkmain >>= maybe (get mkbak) (pure . Just) where - mkmain = genManifestKey (Remote.uuid rmt) Nothing - mkbak = genManifestKey (Remote.uuid rmt) (Just "bak") + mkmain = genManifestKey (Remote.uuid rmt) + mkbak = genBackupManifestKey (Remote.uuid rmt) get mk = getKeyExportLocations rmt mk >>= \case Nothing -> ifM (Remote.checkPresent rmt mk) @@ -654,8 +654,8 @@ uploadManifest rmt manifest = do then void $ dropOldKeys rmt manifest (const True) else uploadfailed where - mkmain = genManifestKey (Remote.uuid rmt) Nothing - mkbak = genManifestKey (Remote.uuid rmt) (Just "bak") + mkmain = genManifestKey (Remote.uuid rmt) + mkbak = genBackupManifestKey (Remote.uuid rmt) uploadfailed = giveup "Failed to upload manifest."