diff options
| author | Joey Hess <joeyh@joeyh.name> | 2017-07-25 15:30:54 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2017-07-25 15:30:54 -0400 |
| commit | 4f5ea9e647de942df53b7fcb0aa69729bd1b1454 (patch) | |
| tree | 7806b879fe5d07879f26f28deec5a10de67c41de /src/Propellor/Property/DiskImage.hs | |
| parent | 9c719f4f5e8b5bfdc0be3259cd3a30b02a345e82 (diff) | |
| parent | f01286bc4338dcb3942b3870d7a6ea69ca773265 (diff) | |
Merge branch 'master' into joeyconfig
Diffstat (limited to 'src/Propellor/Property/DiskImage.hs')
| -rw-r--r-- | src/Propellor/Property/DiskImage.hs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/Propellor/Property/DiskImage.hs b/src/Propellor/Property/DiskImage.hs index 4d10f300..332ad96a 100644 --- a/src/Propellor/Property/DiskImage.hs +++ b/src/Propellor/Property/DiskImage.hs @@ -174,9 +174,7 @@ imageBuiltFrom img chrootdir tabletype final partspec = mkimg <!> rmimg let (mnts, mntopts, parttable) = fitChrootSize tabletype partspec $ map (calcsz mnts) mnts ensureProperty w $ - imageExists img (partTableSize parttable) - `before` - partitioned YesReallyDeleteDiskContents img parttable + imageSetup img parttable `before` kpartx img (mkimg' mnts mntopts parttable) mkimg' mnts mntopts parttable devs = @@ -273,6 +271,24 @@ imageExists img isz = property ("disk image exists" ++ img) $ liftIO $ do -- Common sector sizes are 512 and 4096; use 4096 as it's larger. sectorsize = 4096 :: Double +-- | Ensure that disk image file exists and is partitioned. +-- +-- Avoids repartitioning the disk image, when a file of the right size +-- already exists, and it has the same PartTable. +imageSetup :: FilePath -> PartTable -> Property DebianLike +imageSetup img parttable = property' ("disk image set up " ++ img) $ \w -> do + oldparttable <- liftIO $ catchDefaultIO "" $ readFile parttablefile + res <- ensureProperty w $ imageExists img (partTableSize parttable) + if res == NoChange && oldparttable == show parttable + then return NoChange + else if res == FailedChange + then return FailedChange + else do + liftIO $ writeFile parttablefile (show parttable) + ensureProperty w $ partitioned YesReallyDeleteDiskContents img parttable + where + parttablefile = img ++ ".parttable" + -- | A property that is run after the disk image is created, with -- its populated partition tree mounted in the provided -- location from the provided loop devices. This is typically used to |
