export a more generalized checkDiskSpace
This commit is contained in:
parent
c908bd3b97
commit
262017e17d
2 changed files with 24 additions and 24 deletions
|
@ -127,15 +127,15 @@ getViaTmp key action = do
|
||||||
-- When the temp file already exists, count the space
|
-- When the temp file already exists, count the space
|
||||||
-- it is using as free.
|
-- it is using as free.
|
||||||
e <- liftIO $ doesFileExist tmp
|
e <- liftIO $ doesFileExist tmp
|
||||||
if e
|
alreadythere <- if e
|
||||||
then do
|
then fromIntegral . fileSize <$> liftIO (getFileStatus tmp)
|
||||||
stat <- liftIO $ getFileStatus tmp
|
else return 0
|
||||||
checkDiskSpace' (fromIntegral $ fileSize stat) key
|
ifM (checkDiskSpace Nothing key alreadythere)
|
||||||
else checkDiskSpace key
|
( do
|
||||||
|
when e $ liftIO $ allowWrite tmp
|
||||||
when e $ liftIO $ allowWrite tmp
|
getViaTmpUnchecked key action
|
||||||
|
, return False
|
||||||
getViaTmpUnchecked key action
|
)
|
||||||
|
|
||||||
prepTmp :: Key -> Annex FilePath
|
prepTmp :: Key -> Annex FilePath
|
||||||
prepTmp key = do
|
prepTmp key = do
|
||||||
|
@ -169,22 +169,23 @@ withTmp key action = do
|
||||||
return res
|
return res
|
||||||
|
|
||||||
{- Checks that there is disk space available to store a given key,
|
{- Checks that there is disk space available to store a given key,
|
||||||
- throwing an error if not. -}
|
- in a destination (or the annex) printing a warning if not. -}
|
||||||
checkDiskSpace :: Key -> Annex ()
|
checkDiskSpace :: Maybe FilePath -> Key -> Integer -> Annex Bool
|
||||||
checkDiskSpace = checkDiskSpace' 0
|
checkDiskSpace destination key alreadythere = do
|
||||||
|
|
||||||
checkDiskSpace' :: Integer -> Key -> Annex ()
|
|
||||||
checkDiskSpace' adjustment key = do
|
|
||||||
reserve <- getDiskReserve
|
reserve <- getDiskReserve
|
||||||
free <- inRepo $ getDiskFree . gitAnnexDir
|
free <- liftIO . getDiskFree =<< dir
|
||||||
|
force <- Annex.getState Annex.force
|
||||||
case (free, keySize key) of
|
case (free, keySize key) of
|
||||||
(Just have, Just need) ->
|
(Just have, Just need) -> do
|
||||||
when (need + reserve > have + adjustment) $
|
let ok = need + reserve > have + alreadythere || force
|
||||||
needmorespace (need + reserve - have - adjustment)
|
unless ok $
|
||||||
_ -> return ()
|
needmorespace (need + reserve - have - alreadythere)
|
||||||
|
return ok
|
||||||
|
_ -> return True
|
||||||
where
|
where
|
||||||
needmorespace n = unlessM (Annex.getState Annex.force) $
|
dir = maybe (fromRepo gitAnnexDir) return destination
|
||||||
error $ "not enough free space, need " ++
|
needmorespace n =
|
||||||
|
warning $ "not enough free space, need " ++
|
||||||
roughSize storageUnits True n ++
|
roughSize storageUnits True n ++
|
||||||
" more" ++ forcemsg
|
" more" ++ forcemsg
|
||||||
forcemsg = " (use --force to override this check or adjust annex.diskreserve)"
|
forcemsg = " (use --force to override this check or adjust annex.diskreserve)"
|
||||||
|
|
|
@ -34,8 +34,7 @@ start file (key, _) = do
|
||||||
perform :: FilePath -> Key -> CommandPerform
|
perform :: FilePath -> Key -> CommandPerform
|
||||||
perform dest key = do
|
perform dest key = do
|
||||||
unlessM (inAnnex key) $ error "content not present"
|
unlessM (inAnnex key) $ error "content not present"
|
||||||
|
unlessM (checkDiskSpace Nothing key 0) $ error "cannot unlock"
|
||||||
checkDiskSpace key
|
|
||||||
|
|
||||||
src <- inRepo $ gitAnnexLocation key
|
src <- inRepo $ gitAnnexLocation key
|
||||||
tmpdest <- fromRepo $ gitAnnexTmpLocation key
|
tmpdest <- fromRepo $ gitAnnexTmpLocation key
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue