From 2e49a7e7294a87f8edba5e4835cf02449b991cfe Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 15 Feb 2013 14:17:31 -0400 Subject: [PATCH] don't allow setting indirect mode on a crippled filesystem --- Command/Indirect.hs | 9 ++++++++- Init.hs | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Command/Indirect.hs b/Command/Indirect.hs index e09e3c9bef..90e0b6eafb 100644 --- a/Command/Indirect.hs +++ b/Command/Indirect.hs @@ -16,6 +16,7 @@ import Config import Annex.Direct import Annex.Content import Annex.CatFile +import Init def :: [Command] def = [notBareRepo $ command "indirect" paramNothing seek @@ -25,7 +26,13 @@ seek :: [CommandSeek] seek = [withNothing start] start :: CommandStart -start = ifM isDirect ( next perform, stop ) +start = ifM isDirect + ( ifM probeCrippledFileSystem + ( error "This repository seems to be on a crippled filesystem, you must use direct mode." + , next perform + ) + , stop + ) perform :: CommandPerform perform = do diff --git a/Init.hs b/Init.hs index 77b36b6dd3..b6a04c22ae 100644 --- a/Init.hs +++ b/Init.hs @@ -9,7 +9,8 @@ module Init ( ensureInitialized, isInitialized, initialize, - uninitialize + uninitialize, + probeCrippledFileSystem ) where import Common.Annex @@ -37,7 +38,7 @@ genDescription Nothing = do initialize :: Maybe String -> Annex () initialize mdescription = do prepUUID - probeCrippledFileSystem + checkCrippledFileSystem Annex.Branch.create setVersion gitPreCommitHookWrite @@ -102,18 +103,16 @@ preCommitScript = unlines , "git annex pre-commit ." ] -probeCrippledFileSystem :: Annex () +probeCrippledFileSystem :: Annex Bool probeCrippledFileSystem = do tmp <- fromRepo gitAnnexTmpDir - let f = tmp "init-probe" + let f = tmp "gaprobe" liftIO $ do createDirectoryIfMissing True tmp writeFile f "" - whenM (liftIO $ not <$> probe f) $ do - warning "Detected a crippled filesystem. Enabling direct mode." - setDirect True - setCrippledFileSystem True + uncrippled <- liftIO $ probe f liftIO $ removeFile f + return $ not uncrippled where probe f = catchBoolIO $ do let f2 = f ++ "2" @@ -125,3 +124,9 @@ probeCrippledFileSystem = do preventWrite f allowWrite f return True + +checkCrippledFileSystem :: Annex () +checkCrippledFileSystem = whenM (probeCrippledFileSystem) $ do + warning "Detected a crippled filesystem. Enabling direct mode." + setDirect True + setCrippledFileSystem True