summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2017-10-25 11:48:50 -0400
committerJoey Hess2017-10-25 11:48:50 -0400
commit628f239e0dab82cee2c1b9a1f2818695990df122 (patch)
treeb9260f539dcf6eb126a6e0476528364eb81ab600 /src
parentc693c11b69cfa18d30fbadefbea257bf62c314a6 (diff)
parentb437fa963d7e44945d24c1c5a6453cebcaf7a682 (diff)
Merge remote-tracking branch 'nicolas/ignore-lost-n-found'
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Attic.hs2
-rw-r--r--src/Propellor/Property/Borg.hs2
-rw-r--r--src/Propellor/Property/Chroot.hs4
-rw-r--r--src/Propellor/Property/Chroot/Util.hs4
-rw-r--r--src/Propellor/Property/Debootstrap.hs2
-rw-r--r--src/Propellor/Property/Obnam.hs2
-rw-r--r--src/Propellor/Property/Restic.hs2
-rw-r--r--src/Propellor/Property/Sbuild.hs4
-rw-r--r--src/Utility/Directory.hs19
9 files changed, 26 insertions, 15 deletions
diff --git a/src/Propellor/Property/Attic.hs b/src/Propellor/Property/Attic.hs
index 8ab5546b..f8113e2a 100644
--- a/src/Propellor/Property/Attic.hs
+++ b/src/Propellor/Property/Attic.hs
@@ -59,7 +59,7 @@ restored dir backupdir = go `requires` installed
, noChange
)
- needsRestore = null <$> catchDefaultIO [] (dirContents dir)
+ needsRestore = isUnpopulated dir
restore = withTmpDirIn (takeDirectory dir) "attic-restore" $ \tmpdir -> do
ok <- boolSystem "attic" $
diff --git a/src/Propellor/Property/Borg.hs b/src/Propellor/Property/Borg.hs
index 989fb4b9..49259206 100644
--- a/src/Propellor/Property/Borg.hs
+++ b/src/Propellor/Property/Borg.hs
@@ -95,7 +95,7 @@ restored dir repo = go `requires` installed
, noChange
)
- needsRestore = null <$> catchDefaultIO [] (dirContents dir)
+ needsRestore = isUnpopulated dir
restore = withTmpDirIn (takeDirectory dir) "borg-restore" $ \tmpdir -> do
ok <- runBorg repo $
diff --git a/src/Propellor/Property/Chroot.hs b/src/Propellor/Property/Chroot.hs
index 9e8bcd2f..ea8b1407 100644
--- a/src/Propellor/Property/Chroot.hs
+++ b/src/Propellor/Property/Chroot.hs
@@ -77,7 +77,7 @@ instance ChrootBootstrapper ChrootTarball where
tightenTargets $ extractTarball loc tb
extractTarball :: FilePath -> FilePath -> Property UnixLike
-extractTarball target src = check (unpopulated target) $
+extractTarball target src = check (isUnpopulated target) $
cmdProperty "tar" params
`assume` MadeChange
`requires` File.dirExists target
@@ -151,7 +151,7 @@ provisioned' c@(Chroot loc bootstrapper infopropigator _) systemdonly =
cantbuild e = property (chrootDesc c "built") (error e)
teardown :: Property Linux
- teardown = check (not <$> unpopulated loc) $
+ teardown = check (not <$> isUnpopulated loc) $
property ("removed " ++ loc) $
makeChange (removeChroot loc)
diff --git a/src/Propellor/Property/Chroot/Util.hs b/src/Propellor/Property/Chroot/Util.hs
index ac703136..fd91e984 100644
--- a/src/Propellor/Property/Chroot/Util.hs
+++ b/src/Propellor/Property/Chroot/Util.hs
@@ -27,7 +27,3 @@ 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)
diff --git a/src/Propellor/Property/Debootstrap.hs b/src/Propellor/Property/Debootstrap.hs
index e21bcdff..a9412b95 100644
--- a/src/Propellor/Property/Debootstrap.hs
+++ b/src/Propellor/Property/Debootstrap.hs
@@ -54,7 +54,7 @@ built' :: Property Linux -> FilePath -> System -> DebootstrapConfig -> Property
built' installprop target system@(System _ arch) config =
go `before` oldpermfix
where
- go = check (unpopulated target <||> ispartial) setupprop
+ go = check (isUnpopulated target <||> ispartial) setupprop
`requires` installprop
setupprop :: Property Linux
diff --git a/src/Propellor/Property/Obnam.hs b/src/Propellor/Property/Obnam.hs
index 7943b46e..264d6748 100644
--- a/src/Propellor/Property/Obnam.hs
+++ b/src/Propellor/Property/Obnam.hs
@@ -113,7 +113,7 @@ restored dir params = go `requires` installed
, noChange
)
- needsRestore = null <$> catchDefaultIO [] (dirContents dir)
+ needsRestore = isUnpopulated dir
restore = withTmpDirIn (takeDirectory dir) "obnam-restore" $ \tmpdir -> do
ok <- boolSystem "obnam" $
diff --git a/src/Propellor/Property/Restic.hs b/src/Propellor/Property/Restic.hs
index d9d4d4be..9415f4bf 100644
--- a/src/Propellor/Property/Restic.hs
+++ b/src/Propellor/Property/Restic.hs
@@ -97,7 +97,7 @@ restored dir repo = go
, noChange
)
- needsRestore = null <$> catchDefaultIO [] (dirContents dir)
+ needsRestore = isUnpopulated dir
restore = withTmpDirIn (takeDirectory dir) "restic-restore" $ \tmpdir -> do
ok <- boolSystem "restic"
diff --git a/src/Propellor/Property/Sbuild.hs b/src/Propellor/Property/Sbuild.hs
index 23f3b311..210fb20b 100644
--- a/src/Propellor/Property/Sbuild.hs
+++ b/src/Propellor/Property/Sbuild.hs
@@ -147,7 +147,7 @@ built s@(SbuildSchroot suite arch) mirror cc =
<!> deleted
where
go :: Property DebianLike
- go = check (unpopulated (schrootRoot s) <||> ispartial) $
+ go = check (isUnpopulated (schrootRoot s) <||> ispartial) $
property' ("built sbuild schroot for " ++ val s) make
make w = do
de <- liftIO standardPathEnv
@@ -166,7 +166,7 @@ built s@(SbuildSchroot suite arch) mirror cc =
)
-- TODO we should kill any sessions still using the chroot
-- before destroying it (as suggested by sbuild-destroychroot)
- deleted = check (not <$> unpopulated (schrootRoot s)) $
+ deleted = check (not <$> isUnpopulated (schrootRoot s)) $
property ("no sbuild schroot for " ++ val s) $ do
liftIO $ removeChroot $ schrootRoot s
liftIO $ nukeFile
diff --git a/src/Utility/Directory.hs b/src/Utility/Directory.hs
index 693e7713..86904d63 100644
--- a/src/Utility/Directory.hs
+++ b/src/Utility/Directory.hs
@@ -42,6 +42,10 @@ dirCruft "." = True
dirCruft ".." = True
dirCruft _ = False
+fsCruft :: FilePath -> Bool
+fsCruft "lost+found" = True
+fsCruft d = dirCruft d
+
{- Lists the contents of a directory.
- Unlike getDirectoryContents, paths are not relative to the directory. -}
dirContents :: FilePath -> IO [FilePath]
@@ -236,12 +240,23 @@ readDirectory hdl@(DirectoryHandle _ h fdat mv) = do
-- True only when directory exists and contains nothing.
-- Throws exception if directory does not exist.
isDirectoryEmpty :: FilePath -> IO Bool
-isDirectoryEmpty d = bracket (openDirectory d) closeDirectory check
+isDirectoryEmpty d = testDirectory d dirCruft
+
+-- | True if the directory does not exists or contains nothing, ignoring
+-- "lost+found" which can exists in an empty filesystem.
+isUnpopulated :: FilePath -> IO Bool
+isUnpopulated d = catchDefaultIO True $ testDirectory d fsCruft
+
+-- | Run test on entries found in directory, return False as soon as the
+-- test returns False, else return True. Throws exception if directory does
+-- not exist.
+testDirectory :: FilePath -> (FilePath -> Bool) -> IO Bool
+testDirectory d test = bracket (openDirectory d) closeDirectory check
where
check h = do
v <- readDirectory h
case v of
Nothing -> return True
Just f
- | not (dirCruft f) -> return False
+ | not (test f) -> return False
| otherwise -> check h