summaryrefslogtreecommitdiff
path: root/Annex/Content.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-04-17 21:29:15 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-04-17 21:29:15 -0400
commita5426f14cac3c64299cac62ee6fe86a35f41f584 (patch)
treebf3f3ddcc57bc9b0010277348dbfd850b6d345c1 /Annex/Content.hs
parentf4e1fe5508d4a2de6a777af371457586439493ed (diff)
When a key's size is unknown, still check the annex.diskreserve, and avoid getting content if the disk is too full.
We can't check if there's enough disk space to download the content, but we *can* check if there's certainly not enough!
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r--Annex/Content.hs24
1 files changed, 13 insertions, 11 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index 9d70ccee3..bbf87880b 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -280,17 +280,19 @@ withTmp key action = do
{- Checks that there is disk space available to store a given key,
- in a destination (or the annex) printing a warning if not. -}
checkDiskSpace :: Maybe FilePath -> Key -> Integer -> Annex Bool
-checkDiskSpace destination key alreadythere = do
- reserve <- annexDiskReserve <$> Annex.getGitConfig
- free <- liftIO . getDiskFree =<< dir
- force <- Annex.getState Annex.force
- case (free, keySize key) of
- (Just have, Just need) -> do
- let ok = (need + reserve <= have + alreadythere) || force
- unless ok $
- needmorespace (need + reserve - have - alreadythere)
- return ok
- _ -> return True
+checkDiskSpace destination key alreadythere = ifM (Annex.getState Annex.force)
+ ( return True
+ , do
+ reserve <- annexDiskReserve <$> Annex.getGitConfig
+ free <- liftIO . getDiskFree =<< dir
+ case (free, fromMaybe 1 (keySize key)) of
+ (Just have, need) -> do
+ let ok = (need + reserve <= have + alreadythere)
+ unless ok $
+ needmorespace (need + reserve - have - alreadythere)
+ return ok
+ _ -> return True
+ )
where
dir = maybe (fromRepo gitAnnexDir) return destination
needmorespace n =