simplify code
authorJoey Hess <joeyh@joeyh.name>
Thu, 29 Jul 2021 16:28:13 +0000 (12:28 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 29 Jul 2021 16:28:13 +0000 (12:28 -0400)
Annex/Content.hs
Annex/Content/Presence/LowLevel.hs

index a6ef6a73cda6eefe0b02c9f5d9ea73ee3488e107..5f7b2f39e8b5c641ef6b079d5157251f95abb80b 100644 (file)
@@ -491,28 +491,26 @@ sendAnnex key rollback sendobject = go =<< prepSendAnnex' key
  -}
 prepSendAnnex :: Key -> Annex (Maybe (FilePath, Annex Bool))
 prepSendAnnex key = withObjectLoc key $ \f -> do
+       let retval c = return $ Just (fromRawFilePath f, sameInodeCache f c)
        cache <- Database.Keys.getInodeCaches key
-       cache' <- if null cache
+       if null cache
                -- Since no inode cache is in the database, this
                -- object is not currently unlocked. But that could
                -- change while the transfer is in progress, so
                -- generate an inode cache for the starting
                -- content.
-               then maybeToList <$>
-                       withTSDelta (liftIO . genInodeCache f)
+               then maybe (return Nothing) (retval . (:[]))
+                       =<< withTSDelta (liftIO . genInodeCache f)
                -- Verify that the object is not modified. Usually this
                -- only has to check the inode cache, but if the cache
                -- is somehow stale, it will fall back to verifying its
                -- content.
                else withTSDelta (liftIO . genInodeCache f) >>= \case
                        Just fc -> ifM (isUnmodified' key f fc cache)
-                               ( return (fc:cache)
-                               , return []
+                               ( retval (fc:cache)
+                               , return Nothing
                                )
-                       Nothing -> return []
-       return $ if null cache'
-               then Nothing
-               else Just (fromRawFilePath f, sameInodeCache f cache')
+                       Nothing -> return Nothing
 
 prepSendAnnex' :: Key -> Annex (Maybe (FilePath, Annex (Maybe String)))
 prepSendAnnex' key = prepSendAnnex key >>= \case
index 5d6bb42420a8051691fee0f2945316edf6aeeedb..1191500dfc5e6aeaea3c635c8df9febfe896ee6a 100644 (file)
@@ -14,7 +14,8 @@ import Annex.InodeSentinal
 import Utility.InodeCache
 
 isUnmodifiedLowLevel :: (Key -> [InodeCache] -> Annex ()) -> Key -> RawFilePath -> InodeCache -> [InodeCache] -> Annex Bool
-isUnmodifiedLowLevel addinodecaches key f fc ic = isUnmodifiedCheapLowLevel fc ic <||> expensivecheck
+isUnmodifiedLowLevel addinodecaches key f fc ic =
+       isUnmodifiedCheapLowLevel fc ic <||> expensivecheck
   where
        expensivecheck = ifM (verifyKeyContent RetrievalAllKeysSecure AlwaysVerify UnVerified key f)
                ( do