summaryrefslogtreecommitdiff
path: root/src/Propellor/Property
diff options
context:
space:
mode:
authorSean Whitton2019-04-03 07:49:04 -0700
committerJoey Hess2019-04-03 12:11:52 -0400
commitad13d623f235cbcadba32110172ddd050f8d1322 (patch)
treec0a35250480a1297ae6d37d7e1aed0476365e8ef /src/Propellor/Property
parent9d682a8340ce8b8ada18dd378a9869a71a279427 (diff)
add Mount.partialBindMountsOf function
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/Propellor/Property')
-rw-r--r--src/Propellor/Property/Mount.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Propellor/Property/Mount.hs b/src/Propellor/Property/Mount.hs
index 53129f50..03c4f04d 100644
--- a/src/Propellor/Property/Mount.hs
+++ b/src/Propellor/Property/Mount.hs
@@ -89,6 +89,20 @@ mountPointsBelow target = filter (\p -> simplifyPath p /= simplifyPath target)
. filter (dirContains target)
<$> mountPoints
+-- | Get mountpoints which are bind mounts of subdirectories of mounted
+-- filesystems
+--
+-- E.g. as created by @mount --bind /etc/foo /etc/bar@ where @/etc/foo@ is not
+-- itself a mount point, but just a subdirectory. These are sometimes known as
+-- "partial bind mounts"
+partialBindMountsOf :: FilePath -> IO [MountPoint]
+partialBindMountsOf sourceDir =
+ map (drop 2 . dropWhile (/= ']')) . filter getThem . lines
+ <$> readProcess "findmnt" ["-rn", "--output", "source,target"]
+ where
+ getThem l = bracketed `isSuffixOf` (takeWhile (/= ' ') l)
+ bracketed = "[" ++ sourceDir ++ "]"
+
-- | Filesystem type mounted at a given location.
getFsType :: MountPoint -> IO (Maybe FsType)
getFsType p = findmntField "fstype" [p]