diff options
| author | Joey Hess <joeyh@joeyh.name> | 2017-07-28 22:18:29 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2017-07-28 22:21:29 -0400 |
| commit | ebe81e975882ca3d4fcfe8e80fe9747f0128e2bc (patch) | |
| tree | 56369c47d6bc1143c8f24bf7226c384b135a7f85 /src | |
| parent | 1c37c2e853cf87c84fa36a8f654a450633199b98 (diff) | |
Added Mount.isMounted.
* Added Mount.isMounted.
* Grub.bootsMounted: Bugfix.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Propellor/Property/Grub.hs | 11 | ||||
| -rw-r--r-- | src/Propellor/Property/Mount.hs | 9 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/Propellor/Property/Grub.hs b/src/Propellor/Property/Grub.hs index dbc34f4b..d0516dc8 100644 --- a/src/Propellor/Property/Grub.hs +++ b/src/Propellor/Property/Grub.hs @@ -132,7 +132,12 @@ bootsMounted mnt wholediskdev = combineProperties desc $ props cleanupmounts :: Property Linux cleanupmounts = property desc $ liftIO $ do - umountLazy (inmnt "/sys") - umountLazy (inmnt "/proc") - umountLazy (inmnt "/dev") + cleanup "/sys" + cleanup "/proc" + cleanup "/dev" return NoChange + where + cleanup m = + let mp = inmnt m + in whenM (isMounted mp) $ + umountLazy mp diff --git a/src/Propellor/Property/Mount.hs b/src/Propellor/Property/Mount.hs index 5dcc5fe1..2c4d9620 100644 --- a/src/Propellor/Property/Mount.hs +++ b/src/Propellor/Property/Mount.hs @@ -78,6 +78,10 @@ mount fs src mnt opts = boolSystem "mount" $ mountPoints :: IO [MountPoint] mountPoints = lines <$> readProcess "findmnt" ["-rn", "--output", "target"] +-- | Checks if anything is mounted at the MountPoint. +isMounted :: MountPoint -> IO Bool +isMounted mnt = isJust <$> getFsType mnt + -- | Finds all filesystems mounted inside the specified directory. mountPointsBelow :: FilePath -> IO [MountPoint] mountPointsBelow target = filter (\p -> simplifyPath p /= simplifyPath target) @@ -129,12 +133,15 @@ blkidTag tag dev = catchDefaultIO Nothing $ -- | Unmounts a device or mountpoint, -- lazily so any running processes don't block it. +-- +-- Note that this will fail if it's not mounted. umountLazy :: FilePath -> IO () umountLazy mnt = unlessM (boolSystem "umount" [ Param "-l", Param mnt ]) $ stopPropellorMessage $ "failed unmounting " ++ mnt --- | Unmounts anything mounted inside the specified directory. +-- | Unmounts anything mounted inside the specified directory, +-- not including the directory itself. unmountBelow :: FilePath -> IO () unmountBelow d = do submnts <- mountPointsBelow d |
