aboutsummaryrefslogtreecommitdiff
path: root/Database
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-02-12 14:15:28 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-02-12 14:16:35 -0400
commitad1955b4063befa51a36932794f49193a307a23f (patch)
treeeb358ec9eb692f4418f45ee386053e0859a1626e /Database
parent265cbb0f66881102aa11f73d0cff41c773ddb3a9 (diff)
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.
Diffstat (limited to 'Database')
-rw-r--r--Database/Keys.hs13
-rw-r--r--Database/Keys/Handle.hs4
2 files changed, 11 insertions, 6 deletions
diff --git a/Database/Keys.hs b/Database/Keys.hs
index fe796e206..f3d349dc0 100644
--- a/Database/Keys.hs
+++ b/Database/Keys.hs
@@ -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
diff --git a/Database/Keys/Handle.hs b/Database/Keys/Handle.hs
index 8a3f2b407..51de58fa8 100644
--- a/Database/Keys/Handle.hs
+++ b/Database/Keys/Handle.hs
@@ -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