if keys database cannot be opened due to permissions, ignore

This lets readonly repos be used. If a repo is readonly, we can ignore the
keys database, because nothing that we can do will change the state of the
repo anyway.
This commit is contained in:
Joey Hess 2016-02-12 14:15:28 -04:00
parent 0983f136b8
commit 9df13e73ae
Failed to extract signature
5 changed files with 33 additions and 7 deletions

View file

@ -56,7 +56,7 @@ runReader a = do
h <- getDbHandle
withDbState h go
where
go DbEmpty = return (mempty, DbEmpty)
go DbUnavailable = return (mempty, DbUnavailable)
go st@(DbOpen qh) = do
liftIO $ H.flushDbQueue qh
v <- a (SQL.ReadHandle qh)
@ -114,8 +114,8 @@ getDbHandle = go =<< Annex.getState Annex.keysdbhandle
-}
openDb :: Bool -> DbState -> Annex DbState
openDb _ st@(DbOpen _) = return st
openDb False DbEmpty = return DbEmpty
openDb createdb _ = withExclusiveLock gitAnnexKeysDbLock $ do
openDb False DbUnavailable = return DbUnavailable
openDb createdb _ = catchPermissionDenied permerr $ withExclusiveLock gitAnnexKeysDbLock $ do
dbdir <- fromRepo gitAnnexKeysDb
let db = dbdir </> "db"
dbexists <- liftIO $ doesFileExist db
@ -128,9 +128,14 @@ openDb createdb _ = withExclusiveLock gitAnnexKeysDbLock $ do
setAnnexDirPerm dbdir
setAnnexFilePerm db
open db
(False, False) -> return DbEmpty
(False, False) -> return DbUnavailable
where
open db = liftIO $ DbOpen <$> H.openDbQueue db SQL.containedTable
-- If permissions don't allow opening the database, treat it as if
-- it does not exist.
permerr e = case createdb of
False -> return DbUnavailable
True -> throwM e
addAssociatedFile :: Key -> TopFilePath -> Annex ()
addAssociatedFile k f = runWriterIO $ SQL.addAssociatedFile (toIKey k) f

View file

@ -26,8 +26,8 @@ import Prelude
newtype DbHandle = DbHandle (MVar DbState)
-- The database can be closed or open, but it also may have been
-- tried to open (for read) and didn't exist yet.
data DbState = DbClosed | DbOpen H.DbQueue | DbEmpty
-- tried to open (for read) and didn't exist yet or is not readable.
data DbState = DbClosed | DbOpen H.DbQueue | DbUnavailable
newDbHandle :: IO DbHandle
newDbHandle = DbHandle <$> newMVar DbClosed

View file

@ -21,7 +21,8 @@ module Utility.Exception (
tryNonAsync,
tryWhenExists,
catchIOErrorType,
IOErrorType(..)
IOErrorType(..),
catchPermissionDenied,
) where
import Control.Monad.Catch as X hiding (Handler)
@ -97,3 +98,6 @@ catchIOErrorType errtype onmatchingerr a = catchIO a onlymatching
onlymatching e
| ioeGetErrorType e == errtype = onmatchingerr e
| otherwise = throwM e
catchPermissionDenied :: MonadCatch m => (IOException -> m a) -> m a -> m a
catchPermissionDenied = catchIOErrorType PermissionDenied

6
debian/changelog vendored
View file

@ -1,3 +1,9 @@
git-annex (6.20160212) UNRELEASED; urgency=medium
* Support getting files from read-only repositories.
-- Joey Hess <id@joeyh.name> Fri, 12 Feb 2016 14:03:46 -0400
git-annex (6.20160211) unstable; urgency=medium
* annex.addsmallfiles: New option controlling what is done when

View file

@ -0,0 +1,11 @@
[[!comment format=mdwn
username="joey"
subject="""comment 8"""
date="2016-02-12T18:08:18Z"
content="""
I've made some changes today, which let files be downloaded from readonly
repositories (both on local drives and remote, as long as git-annex-shell
is updated to a version with the changes).
The issues with the webapp probably remain.
"""]]