From 67cb5eaecccddf65ecbd949aad6e82f6694ad4e5 Mon Sep 17 00:00:00 2001 From: FĂ©lix Sipma Date: Fri, 29 Apr 2016 11:21:02 +0200 Subject: Attic: use/adapt restored from Obnam --- src/Propellor/Property/Attic.hs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'src/Propellor/Property/Attic.hs') diff --git a/src/Propellor/Property/Attic.hs b/src/Propellor/Property/Attic.hs index 504e3cfb..ef74afbd 100644 --- a/src/Propellor/Property/Attic.hs +++ b/src/Propellor/Property/Attic.hs @@ -34,18 +34,33 @@ init backupdir = check (not <$> repoExists backupdir) (cmdProperty "attic" inita , backupdir ] --- TODO: use restored from Obnam restored :: FilePath -> AtticRepo -> Property DebianLike -restored dir backupdir = cmdProperty "attic" restoreargs - `assume` MadeChange - `describe` ("attic restore from " ++ backupdir) - `requires` installed +restored dir backupdir = go `requires` installed where - restoreargs = - [ "extract" - , backupdir - , dir - ] + go :: Property DebianLike + go = property (dir ++ " restored by attic") $ ifM (liftIO needsRestore) + ( do + warningMessage $ dir ++ " is empty/missing; restoring from backup ..." + liftIO restore + , noChange + ) + + needsRestore = null <$> catchDefaultIO [] (dirContents dir) + + restore = withTmpDirIn (takeDirectory dir) "attic-restore" $ \tmpdir -> do + ok <- boolSystem "attic" $ + [ Param "extract" + , Param backupdir + , Param tmpdir + ] + let restoreddir = tmpdir ++ "/" ++ dir + ifM (pure ok <&&> doesDirectoryExist restoreddir) + ( do + void $ tryIO $ removeDirectory dir + renameDirectory restoreddir dir + return MadeChange + , return FailedChange + ) backup :: FilePath -> AtticRepo -> Cron.Times -> [AtticParam] -> [KeepPolicy] -> Property DebianLike backup dir backupdir crontimes extraargs kp = backup' dir backupdir crontimes extraargs kp -- cgit v1.2.3