summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Whitton2019-04-03 07:49:05 -0700
committerJoey Hess2019-04-03 12:11:52 -0400
commit5bc19af29effa14804588fdb062b65ee8fd75bcd (patch)
treef73ec7d74b8dab5b303327b19ca275124076c688 /src
parentad13d623f235cbcadba32110172ddd050f8d1322 (diff)
add Localdir.removed
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Localdir.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Propellor/Property/Localdir.hs b/src/Propellor/Property/Localdir.hs
index 5d8e2033..018a054b 100644
--- a/src/Propellor/Property/Localdir.hs
+++ b/src/Propellor/Property/Localdir.hs
@@ -7,6 +7,8 @@ module Propellor.Property.Localdir where
import Propellor.Base
import Propellor.Git.Config
import Propellor.Types.Info
+import Propellor.Property.Chroot (inChroot)
+import Propellor.Property.Mount (partialBindMountsOf, umountLazy)
-- | Sets the url to use as the origin of propellor's git repository.
--
@@ -29,3 +31,31 @@ hasOriginUrl u = setInfoProperty p (toInfo (InfoVal (OriginUrl u)))
newtype OriginUrl = OriginUrl String
deriving (Show, Typeable)
+
+-- | Removes the @/usr/local/propellor@ directory used to spin the host, after
+-- ensuring other properties. Without this property, that directory is left
+-- behind after the spin.
+--
+-- Does not perform other clean up, such as removing Haskell libraries that were
+-- installed in order to build propellor, or removing cronjobs such as created
+-- by 'Propellor.Property.Cron.runPropellor'.
+removed :: Property UnixLike
+removed = check (doesDirectoryExist localdir) $
+ property "propellor's /usr/local dir to be removed" $ do
+ endAction "removing /usr/local/propellor" atend
+ return NoChange
+ where
+ atend _ = do
+ ifM inChroot
+ -- In a chroot, all we have to do is unmount localdir,
+ -- and then delete it
+ ( liftIO $ umountLazy localdir
+ -- Outside of a chroot, if we don't unmount any bind
+ -- mounts of localdir before deleting it, another run of
+ -- propellor will have problems reestablishing those
+ -- bind mounts in order to spin chroots
+ , liftIO $ partialBindMountsOf localdir
+ >>= mapM_ umountLazy
+ )
+ liftIO $ removeDirectoryRecursive localdir
+ return NoChange