summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma2016-04-29 11:21:02 +0200
committerFélix Sipma2016-04-29 11:21:02 +0200
commit67cb5eaecccddf65ecbd949aad6e82f6694ad4e5 (patch)
treee8cf7f1ba0c48d99839b5d1daba4a05ab99a0c4b
parented52eec11b61d59b7a139b8f55c59961b0806d96 (diff)
Attic: use/adapt restored from Obnam
-rw-r--r--src/Propellor/Property/Attic.hs35
1 files changed, 25 insertions, 10 deletions
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