aboutsummaryrefslogtreecommitdiff
path: root/Command/Uninit.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-07-12 14:18:35 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-07-12 14:18:35 -0400
commit8a7b972e55fa6eaa4c754303b3ee8fd214a51468 (patch)
treecb41dbe7b3bb265a22b6d61631e5e27ab3e187fa /Command/Uninit.hs
parent50c57ea1c0ec659e565578e9011e3111e6b11898 (diff)
uninit: Fix crash due to trying to write to deleted keys db.
Reversion introduced by v6 mode support, affects v5 too. Also fix a similar crash when the webapp is used to delete a repository.
Diffstat (limited to 'Command/Uninit.hs')
-rw-r--r--Command/Uninit.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/Command/Uninit.hs b/Command/Uninit.hs
index 44f4b0ded..fa7e13013 100644
--- a/Command/Uninit.hs
+++ b/Command/Uninit.hs
@@ -13,6 +13,7 @@ import qualified Git
import qualified Git.Command
import qualified Command.Unannex
import qualified Annex.Branch
+import qualified Database.Keys
import Annex.Content
import Annex.Init
import Utility.FileMode
@@ -61,7 +62,7 @@ finish = do
annexdir <- fromRepo gitAnnexDir
annexobjectdir <- fromRepo gitAnnexObjectDir
leftovers <- removeUnannexed =<< getKeysPresent InAnnex
- liftIO $ prepareRemoveAnnexDir annexdir
+ prepareRemoveAnnexDir annexdir
if null leftovers
then liftIO $ removeDirectoryRecursive annexdir
else error $ unlines
@@ -89,9 +90,17 @@ finish = do
liftIO exitSuccess
{- Turn on write bits in all remaining files in the annex directory, in
- - preparation for removal. -}
-prepareRemoveAnnexDir :: FilePath -> IO ()
-prepareRemoveAnnexDir annexdir =
+ - preparation for removal.
+ -
+ - Also closes sqlite databases that might be in the directory,
+ - to avoid later failure to write any cached changes to them. -}
+prepareRemoveAnnexDir :: FilePath -> Annex ()
+prepareRemoveAnnexDir annexdir = do
+ Database.Keys.closeDb
+ liftIO $ prepareRemoveAnnexDir' annexdir
+
+prepareRemoveAnnexDir' :: FilePath -> IO ()
+prepareRemoveAnnexDir' annexdir =
recurseDir SystemFS annexdir >>= mapM_ (void . tryIO . allowWrite)
{- Keys that were moved out of the annex have a hard link still in the