annex.diskreserve can be given in arbitrary units (ie "0.5 gigabytes")
This commit is contained in:
parent
ceb9593a9c
commit
8bcdf42b99
5 changed files with 27 additions and 12 deletions
|
@ -198,6 +198,6 @@ checkKeySize key = do
|
||||||
else do
|
else do
|
||||||
dest <- moveBad key
|
dest <- moveBad key
|
||||||
warning $ "Bad file size (" ++
|
warning $ "Bad file size (" ++
|
||||||
compareSizes True size size' ++
|
compareSizes storageUnits True size size' ++
|
||||||
"); moved to " ++ dest
|
"); moved to " ++ dest
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -122,7 +122,9 @@ checkDiskSpace' :: Integer -> Key -> Annex ()
|
||||||
checkDiskSpace' adjustment key = do
|
checkDiskSpace' adjustment key = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
r <- Annex.repoConfig g "diskreserve" ""
|
r <- Annex.repoConfig g "diskreserve" ""
|
||||||
let reserve = if null r then megabyte else (read r :: Integer)
|
let reserve = case readSize dataUnits r of
|
||||||
|
Nothing -> megabyte
|
||||||
|
Just v -> v
|
||||||
stats <- liftIO $ getFileSystemStats (gitAnnexDir g)
|
stats <- liftIO $ getFileSystemStats (gitAnnexDir g)
|
||||||
case (stats, keySize key) of
|
case (stats, keySize key) of
|
||||||
(Nothing, _) -> return ()
|
(Nothing, _) -> return ()
|
||||||
|
@ -133,12 +135,12 @@ checkDiskSpace' adjustment key = do
|
||||||
else return ()
|
else return ()
|
||||||
where
|
where
|
||||||
megabyte :: Integer
|
megabyte :: Integer
|
||||||
megabyte = 1024 * 1024
|
megabyte = 1000000
|
||||||
needmorespace n = do
|
needmorespace n = do
|
||||||
force <- Annex.getState Annex.force
|
force <- Annex.getState Annex.force
|
||||||
unless force $
|
unless force $
|
||||||
error $ "not enough free space, need " ++
|
error $ "not enough free space, need " ++
|
||||||
roughSize True n ++
|
roughSize storageUnits True n ++
|
||||||
" more (use --force to override this check or adjust annex.diskreserve)"
|
" more (use --force to override this check or adjust annex.diskreserve)"
|
||||||
|
|
||||||
{- Removes the write bits from a file. -}
|
{- Removes the write bits from a file. -}
|
||||||
|
|
17
DataUnits.hs
17
DataUnits.hs
|
@ -11,7 +11,8 @@ module DataUnits (
|
||||||
memoryUnits,
|
memoryUnits,
|
||||||
oldSchoolUnits,
|
oldSchoolUnits,
|
||||||
roughSize,
|
roughSize,
|
||||||
compareSizes
|
compareSizes,
|
||||||
|
readSize
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
|
@ -53,6 +54,7 @@ data Unit = Unit ByteSize Abbrev Name
|
||||||
- progress?
|
- progress?
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
dataUnits :: [Unit]
|
||||||
dataUnits = storageUnits ++ memoryUnits
|
dataUnits = storageUnits ++ memoryUnits
|
||||||
|
|
||||||
{- Storage units are (stupidly) powers of ten. -}
|
{- Storage units are (stupidly) powers of ten. -}
|
||||||
|
@ -69,6 +71,7 @@ storageUnits =
|
||||||
, Unit (p 0) "B" "byte"
|
, Unit (p 0) "B" "byte"
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
|
p :: Integer -> Integer
|
||||||
p n = 1000^n
|
p n = 1000^n
|
||||||
|
|
||||||
{- Memory units are (stupidly named) powers of 2. -}
|
{- Memory units are (stupidly named) powers of 2. -}
|
||||||
|
@ -85,12 +88,14 @@ memoryUnits =
|
||||||
, Unit (p 0) "B" "byte"
|
, Unit (p 0) "B" "byte"
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
|
p :: Integer -> Integer
|
||||||
p n = 2^(n*10)
|
p n = 2^(n*10)
|
||||||
|
|
||||||
{- Do you yearn for the days when men were men and megabytes were megabytes? -}
|
{- Do you yearn for the days when men were men and megabytes were megabytes? -}
|
||||||
|
oldSchoolUnits :: [Unit]
|
||||||
oldSchoolUnits = map mingle $ zip storageUnits memoryUnits
|
oldSchoolUnits = map mingle $ zip storageUnits memoryUnits
|
||||||
where
|
where
|
||||||
mingle (Unit s a n, Unit s' a' n') = Unit s' a n
|
mingle (Unit _ a n, Unit s' _ _) = Unit s' a n
|
||||||
|
|
||||||
{- approximate display of a particular number of bytes -}
|
{- approximate display of a particular number of bytes -}
|
||||||
roughSize :: [Unit] -> Bool -> ByteSize -> String
|
roughSize :: [Unit] -> Bool -> ByteSize -> String
|
||||||
|
@ -124,8 +129,8 @@ compareSizes units abbrev old new
|
||||||
| otherwise = "same"
|
| otherwise = "same"
|
||||||
|
|
||||||
{- Parses strings like "10 kilobytes" or "0.5tb". -}
|
{- Parses strings like "10 kilobytes" or "0.5tb". -}
|
||||||
readSize :: String -> [Unit] -> Maybe ByteSize
|
readSize :: [Unit] -> String -> Maybe ByteSize
|
||||||
readSize s units
|
readSize units input
|
||||||
| null parsednum = Nothing
|
| null parsednum = Nothing
|
||||||
| null parsedunit = Nothing
|
| null parsedunit = Nothing
|
||||||
| otherwise = Just $ round $ number * (fromIntegral multiplier)
|
| otherwise = Just $ round $ number * (fromIntegral multiplier)
|
||||||
|
@ -133,14 +138,14 @@ readSize s units
|
||||||
(number, rest) = head parsednum
|
(number, rest) = head parsednum
|
||||||
multiplier = head $ parsedunit
|
multiplier = head $ parsedunit
|
||||||
|
|
||||||
parsednum = reads s :: [(Double, String)]
|
parsednum = reads input :: [(Double, String)]
|
||||||
parsedunit = lookupUnit units unit
|
parsedunit = lookupUnit units unit
|
||||||
|
|
||||||
unit = takeWhile isAlpha $ dropWhile isSpace rest
|
unit = takeWhile isAlpha $ dropWhile isSpace rest
|
||||||
|
|
||||||
lookupUnit _ [] = [1] -- no unit given, assume bytes
|
lookupUnit _ [] = [1] -- no unit given, assume bytes
|
||||||
lookupUnit [] _ = []
|
lookupUnit [] _ = []
|
||||||
lookupUnit (u@(Unit s a n):us) v
|
lookupUnit (Unit s a n:us) v
|
||||||
| a ~~ v || n ~~ v = [s]
|
| a ~~ v || n ~~ v = [s]
|
||||||
| plural n ~~ v || a ~~ byteabbrev v = [s]
|
| plural n ~~ v || a ~~ byteabbrev v = [s]
|
||||||
| otherwise = lookupUnit us v
|
| otherwise = lookupUnit us v
|
||||||
|
|
6
debian/changelog
vendored
6
debian/changelog
vendored
|
@ -1,3 +1,9 @@
|
||||||
|
git-annex (0.20110326) UNRELEASED; urgency=low
|
||||||
|
|
||||||
|
* annex.diskreserve can be given in arbitrary units (ie "0.5 gigabytes")
|
||||||
|
|
||||||
|
-- Joey Hess <joeyh@debian.org> Sat, 26 Mar 2011 14:36:16 -0400
|
||||||
|
|
||||||
git-annex (0.20110325) experimental; urgency=low
|
git-annex (0.20110325) experimental; urgency=low
|
||||||
|
|
||||||
* Free space checking is now done, for transfers of data for keys
|
* Free space checking is now done, for transfers of data for keys
|
||||||
|
|
|
@ -387,8 +387,10 @@ Here are all the supported configuration settings.
|
||||||
Amount of disk space to reserve. Disk space is checked when transferring
|
Amount of disk space to reserve. Disk space is checked when transferring
|
||||||
content to avoid running out, and additional free space can be reserved
|
content to avoid running out, and additional free space can be reserved
|
||||||
via this option, to make space for more important content (such as git
|
via this option, to make space for more important content (such as git
|
||||||
commit logs). The units are bytes.
|
commit logs). Can be specified with any commonly used units, for example,
|
||||||
The default reserve is 1048576 (1 megabyte).
|
"0.5 gb" or "100 KiloBytes"
|
||||||
|
|
||||||
|
The default reserve is 1 megabyte.
|
||||||
|
|
||||||
* `annex.version`
|
* `annex.version`
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue