summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Chroot/Util.hs
diff options
context:
space:
mode:
authorJoey Hess2015-10-20 12:01:59 -0400
committerJoey Hess2015-10-20 12:06:24 -0400
commit05d35eb568e74deafc936e6735171291410b5f0b (patch)
tree3d1f25930948f59c96b942ec296b11094f3f20c3 /src/Propellor/Property/Chroot/Util.hs
parentbfcc5a7666f817fbfe9c149480ca0359e3e744ec (diff)
Chroot: Converted to use a ChrootBootstrapper type class
So other ways to bootstrap chroots can easily be added in separate modules. (API change)
Diffstat (limited to 'src/Propellor/Property/Chroot/Util.hs')
-rw-r--r--src/Propellor/Property/Chroot/Util.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Propellor/Property/Chroot/Util.hs b/src/Propellor/Property/Chroot/Util.hs
index ea0df780..3ebda28f 100644
--- a/src/Propellor/Property/Chroot/Util.hs
+++ b/src/Propellor/Property/Chroot/Util.hs
@@ -2,11 +2,14 @@ module Propellor.Property.Chroot.Util where
import Propellor.Property.Mount
+import Utility.Exception
import Utility.Env
+import Utility.Directory
+
import Control.Applicative
import System.Directory
--- When chrooting, it's useful to ensure that PATH has all the standard
+-- | When chrooting, it's useful to ensure that PATH has all the standard
-- directories in it. This adds those directories to whatever PATH is
-- already set.
standardPathEnv :: IO [(String, String)]
@@ -18,9 +21,13 @@ standardPathEnv = do
stdPATH :: String
stdPATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
--- Removes the contents of a chroot. First, unmounts any filesystems
+-- | Removes the contents of a chroot. First, unmounts any filesystems
-- mounted within it.
removeChroot :: FilePath -> IO ()
removeChroot c = do
unmountBelow c
removeDirectoryRecursive c
+
+-- | Returns true if a chroot directory is empty.
+unpopulated :: FilePath -> IO Bool
+unpopulated d = null <$> catchDefaultIO [] (dirContents d)