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!
This commit is contained in:
Joey Hess 2015-04-17 21:29:15 -04:00
parent 894a8948be
commit 3a078ab357
2 changed files with 15 additions and 11 deletions

View file

@ -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 =

2
debian/changelog vendored
View file

@ -12,6 +12,8 @@ git-annex (5.20150410) UNRELEASED; urgency=medium
* bittorrent: Fix handling of magnet links.
* Windows: Fixed support of remotes on other drives.
(A reversion introduced in version 5.20150113.)
* When a key's size is unknown, still check the annex.diskreserve,
and avoid getting content if the disk is too full.
-- Joey Hess <id@joeyh.name> Thu, 09 Apr 2015 20:59:43 -0400