don't allow setting indirect mode on a crippled filesystem

This commit is contained in:
Joey Hess 2013-02-15 14:17:31 -04:00
parent 4da932a48f
commit 2e49a7e729
2 changed files with 21 additions and 9 deletions

View file

@ -16,6 +16,7 @@ import Config
import Annex.Direct import Annex.Direct
import Annex.Content import Annex.Content
import Annex.CatFile import Annex.CatFile
import Init
def :: [Command] def :: [Command]
def = [notBareRepo $ command "indirect" paramNothing seek def = [notBareRepo $ command "indirect" paramNothing seek
@ -25,7 +26,13 @@ seek :: [CommandSeek]
seek = [withNothing start] seek = [withNothing start]
start :: CommandStart 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 :: CommandPerform
perform = do perform = do

21
Init.hs
View file

@ -9,7 +9,8 @@ module Init (
ensureInitialized, ensureInitialized,
isInitialized, isInitialized,
initialize, initialize,
uninitialize uninitialize,
probeCrippledFileSystem
) where ) where
import Common.Annex import Common.Annex
@ -37,7 +38,7 @@ genDescription Nothing = do
initialize :: Maybe String -> Annex () initialize :: Maybe String -> Annex ()
initialize mdescription = do initialize mdescription = do
prepUUID prepUUID
probeCrippledFileSystem checkCrippledFileSystem
Annex.Branch.create Annex.Branch.create
setVersion setVersion
gitPreCommitHookWrite gitPreCommitHookWrite
@ -102,18 +103,16 @@ preCommitScript = unlines
, "git annex pre-commit ." , "git annex pre-commit ."
] ]
probeCrippledFileSystem :: Annex () probeCrippledFileSystem :: Annex Bool
probeCrippledFileSystem = do probeCrippledFileSystem = do
tmp <- fromRepo gitAnnexTmpDir tmp <- fromRepo gitAnnexTmpDir
let f = tmp </> "init-probe" let f = tmp </> "gaprobe"
liftIO $ do liftIO $ do
createDirectoryIfMissing True tmp createDirectoryIfMissing True tmp
writeFile f "" writeFile f ""
whenM (liftIO $ not <$> probe f) $ do uncrippled <- liftIO $ probe f
warning "Detected a crippled filesystem. Enabling direct mode."
setDirect True
setCrippledFileSystem True
liftIO $ removeFile f liftIO $ removeFile f
return $ not uncrippled
where where
probe f = catchBoolIO $ do probe f = catchBoolIO $ do
let f2 = f ++ "2" let f2 = f ++ "2"
@ -125,3 +124,9 @@ probeCrippledFileSystem = do
preventWrite f preventWrite f
allowWrite f allowWrite f
return True return True
checkCrippledFileSystem :: Annex ()
checkCrippledFileSystem = whenM (probeCrippledFileSystem) $ do
warning "Detected a crippled filesystem. Enabling direct mode."
setDirect True
setCrippledFileSystem True