From 474119770bd54a905fcdda25a7bb12f2b1ea1307 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 25 Aug 2015 21:48:31 -0700 Subject: idempotency fix for kpartx noticed kpartx could get confused if a disk image it had mapped was deleted and a fresh one mapped --- src/Propellor/Property/Partition.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Propellor/Property/Partition.hs') diff --git a/src/Propellor/Property/Partition.hs b/src/Propellor/Property/Partition.hs index 53d8a946..41bdf795 100644 --- a/src/Propellor/Property/Partition.hs +++ b/src/Propellor/Property/Partition.hs @@ -45,10 +45,12 @@ kpartx :: FilePath -> ([FilePath] -> Property NoInfo) -> Property NoInfo kpartx diskimage mkprop = go `requires` Apt.installed ["kpartx"] where go = property (propertyDesc (mkprop [])) $ do + cleanup -- idempotency s <- liftIO $ readProcess "kpartx" ["-avs", diskimage] r <- ensureProperty (mkprop (devlist s)) - void $ liftIO $ boolSystem "kpartx" [Param "-d", File diskimage] + cleanup return r devlist = mapMaybe (finddev . words) . lines finddev ("add":"map":s:_) = Just ("/dev/mapper/" ++ s) finddev _ = Nothing + cleanup = void $ liftIO $ boolSystem "kpartx" [Param "-d", File diskimage] -- cgit v1.2.3