From 57cceac569c7ae08d76a2ee17105416f4dfcfab0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 3 Jul 2020 14:22:22 -0400 Subject: [PATCH] simplify interface by removing size Add size to the returned key after the fact, unless the remote happened to add it itself. --- Annex/Import.hs | 6 +++++- Remote/Directory.hs | 4 ++-- Types/Remote.hs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Annex/Import.hs b/Annex/Import.hs index 76ac6cff7f..44877bc0c8 100644 --- a/Annex/Import.hs +++ b/Annex/Import.hs @@ -391,7 +391,11 @@ importKeys remote importtreeconfig importcontent importablecontents = do Nothing -> error "internal" -- checked earlier Just a -> do let importer p = do - k <- a loc cid sz p + unsizedk <- a loc cid p + -- This avoids every remote needing + -- to add the size. + let k = alterKey unsizedk $ \kd -> kd + { keySize = keySize kd <|> Just sz } checkSecureHashes k >>= \case Nothing -> do recordcidkey cidmap db cid k diff --git a/Remote/Directory.hs b/Remote/Directory.hs index 9b22b1f8d1..8d320c6707 100644 --- a/Remote/Directory.hs +++ b/Remote/Directory.hs @@ -350,8 +350,8 @@ guardSameContentIdentifiers cont old new | new == Just old = cont | otherwise = giveup "file content has changed" -importKeyM :: FilePath -> ExportLocation -> ContentIdentifier -> ByteSize -> MeterUpdate -> Annex Key -importKeyM dir loc cid sz p = do +importKeyM :: FilePath -> ExportLocation -> ContentIdentifier -> MeterUpdate -> Annex Key +importKeyM dir loc cid p = do backend <- chooseBackend (fromRawFilePath f) k <- fst <$> genKey ks p backend currcid <- liftIO $ mkContentIdentifier absf =<< getFileStatus absf diff --git a/Types/Remote.hs b/Types/Remote.hs index f04266a890..ca30f32dfd 100644 --- a/Types/Remote.hs +++ b/Types/Remote.hs @@ -287,7 +287,7 @@ data ImportActions a = ImportActions -- since the ContentIdentifier was generated. -- -- Throws exception on failure. - , importKey :: Maybe (ExportLocation -> ContentIdentifier -> ByteSize -> MeterUpdate -> a Key) + , importKey :: Maybe (ExportLocation -> ContentIdentifier -> MeterUpdate -> a Key) -- Retrieves a file from the remote. Ensures that the file -- it retrieves has the requested ContentIdentifier. --