summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/DiskImage.hs
diff options
context:
space:
mode:
authorJoey Hess2017-12-20 19:01:42 -0400
committerJoey Hess2017-12-20 19:01:42 -0400
commit9beb0011f00b591757db34873e1b8fc353ff7e75 (patch)
tree079524054e4f148346bb812eca6f90f8d5256e63 /src/Propellor/Property/DiskImage.hs
parenta833f0f171bb718a053784cef564095d69779638 (diff)
say when resizing/creating disk image file
That can take quite a while, so let the user know why propellor has stalled.
Diffstat (limited to 'src/Propellor/Property/DiskImage.hs')
-rw-r--r--src/Propellor/Property/DiskImage.hs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/Propellor/Property/DiskImage.hs b/src/Propellor/Property/DiskImage.hs
index c9998d3c..1f4f8118 100644
--- a/src/Propellor/Property/DiskImage.hs
+++ b/src/Propellor/Property/DiskImage.hs
@@ -41,6 +41,7 @@ import Propellor.Types.Bootloader
import Propellor.Container
import Utility.Path
import Utility.FileMode
+import Utility.DataUnits
import Data.List (isPrefixOf, isInfixOf, sortBy, unzip4)
import Data.Function (on)
@@ -344,17 +345,24 @@ getMountSz szm l (Just mntpt) =
imageExists :: RawDiskImage -> ByteSize -> Property Linux
imageExists (RawDiskImage img) isz = property ("disk image exists" ++ img) $ liftIO $ do
ms <- catchMaybeIO $ getFileStatus img
- case ms of
+ case fmap (toInteger . fileSize) ms of
Just s
- | toInteger (fileSize s) == toInteger sz -> return NoChange
- | toInteger (fileSize s) > toInteger sz -> do
+ | s == toInteger sz -> return NoChange
+ | s > toInteger sz -> do
+ infoMessage ["truncating " ++ img ++ " to " ++ humansz]
setFileSize img (fromInteger sz)
return MadeChange
- _ -> do
+ | otherwise -> do
+ infoMessage ["expanding " ++ img ++ " from " ++ roughSize storageUnits False s ++ " to " ++ humansz]
+ L.writeFile img (L.replicate (fromIntegral sz) 0)
+ return MadeChange
+ Nothing -> do
+ infoMessage ["creating " ++ img ++ " of size " ++ humansz]
L.writeFile img (L.replicate (fromIntegral sz) 0)
return MadeChange
where
sz = ceiling (fromInteger isz / sectorsize) * ceiling sectorsize
+ humansz = roughSize storageUnits False (toInteger sz)
-- Disks have a sector size, and making a disk image not
-- aligned to a sector size will confuse some programs.
-- Common sector sizes are 512 and 4096; use 4096 as it's larger.