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:
parent
0983f136b8
commit
9df13e73ae
5 changed files with 33 additions and 7 deletions
|
@ -56,7 +56,7 @@ runReader a = do
|
||||||
h <- getDbHandle
|
h <- getDbHandle
|
||||||
withDbState h go
|
withDbState h go
|
||||||
where
|
where
|
||||||
go DbEmpty = return (mempty, DbEmpty)
|
go DbUnavailable = return (mempty, DbUnavailable)
|
||||||
go st@(DbOpen qh) = do
|
go st@(DbOpen qh) = do
|
||||||
liftIO $ H.flushDbQueue qh
|
liftIO $ H.flushDbQueue qh
|
||||||
v <- a (SQL.ReadHandle qh)
|
v <- a (SQL.ReadHandle qh)
|
||||||
|
@ -114,8 +114,8 @@ getDbHandle = go =<< Annex.getState Annex.keysdbhandle
|
||||||
-}
|
-}
|
||||||
openDb :: Bool -> DbState -> Annex DbState
|
openDb :: Bool -> DbState -> Annex DbState
|
||||||
openDb _ st@(DbOpen _) = return st
|
openDb _ st@(DbOpen _) = return st
|
||||||
openDb False DbEmpty = return DbEmpty
|
openDb False DbUnavailable = return DbUnavailable
|
||||||
openDb createdb _ = withExclusiveLock gitAnnexKeysDbLock $ do
|
openDb createdb _ = catchPermissionDenied permerr $ withExclusiveLock gitAnnexKeysDbLock $ do
|
||||||
dbdir <- fromRepo gitAnnexKeysDb
|
dbdir <- fromRepo gitAnnexKeysDb
|
||||||
let db = dbdir </> "db"
|
let db = dbdir </> "db"
|
||||||
dbexists <- liftIO $ doesFileExist db
|
dbexists <- liftIO $ doesFileExist db
|
||||||
|
@ -128,9 +128,14 @@ openDb createdb _ = withExclusiveLock gitAnnexKeysDbLock $ do
|
||||||
setAnnexDirPerm dbdir
|
setAnnexDirPerm dbdir
|
||||||
setAnnexFilePerm db
|
setAnnexFilePerm db
|
||||||
open db
|
open db
|
||||||
(False, False) -> return DbEmpty
|
(False, False) -> return DbUnavailable
|
||||||
where
|
where
|
||||||
open db = liftIO $ DbOpen <$> H.openDbQueue db SQL.containedTable
|
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 :: Key -> TopFilePath -> Annex ()
|
||||||
addAssociatedFile k f = runWriterIO $ SQL.addAssociatedFile (toIKey k) f
|
addAssociatedFile k f = runWriterIO $ SQL.addAssociatedFile (toIKey k) f
|
||||||
|
|
|
@ -26,8 +26,8 @@ import Prelude
|
||||||
newtype DbHandle = DbHandle (MVar DbState)
|
newtype DbHandle = DbHandle (MVar DbState)
|
||||||
|
|
||||||
-- The database can be closed or open, but it also may have been
|
-- The database can be closed or open, but it also may have been
|
||||||
-- tried to open (for read) and didn't exist yet.
|
-- tried to open (for read) and didn't exist yet or is not readable.
|
||||||
data DbState = DbClosed | DbOpen H.DbQueue | DbEmpty
|
data DbState = DbClosed | DbOpen H.DbQueue | DbUnavailable
|
||||||
|
|
||||||
newDbHandle :: IO DbHandle
|
newDbHandle :: IO DbHandle
|
||||||
newDbHandle = DbHandle <$> newMVar DbClosed
|
newDbHandle = DbHandle <$> newMVar DbClosed
|
||||||
|
|
|
@ -21,7 +21,8 @@ module Utility.Exception (
|
||||||
tryNonAsync,
|
tryNonAsync,
|
||||||
tryWhenExists,
|
tryWhenExists,
|
||||||
catchIOErrorType,
|
catchIOErrorType,
|
||||||
IOErrorType(..)
|
IOErrorType(..),
|
||||||
|
catchPermissionDenied,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Catch as X hiding (Handler)
|
import Control.Monad.Catch as X hiding (Handler)
|
||||||
|
@ -97,3 +98,6 @@ catchIOErrorType errtype onmatchingerr a = catchIO a onlymatching
|
||||||
onlymatching e
|
onlymatching e
|
||||||
| ioeGetErrorType e == errtype = onmatchingerr e
|
| ioeGetErrorType e == errtype = onmatchingerr e
|
||||||
| otherwise = throwM e
|
| otherwise = throwM e
|
||||||
|
|
||||||
|
catchPermissionDenied :: MonadCatch m => (IOException -> m a) -> m a -> m a
|
||||||
|
catchPermissionDenied = catchIOErrorType PermissionDenied
|
||||||
|
|
6
debian/changelog
vendored
6
debian/changelog
vendored
|
@ -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
|
git-annex (6.20160211) unstable; urgency=medium
|
||||||
|
|
||||||
* annex.addsmallfiles: New option controlling what is done when
|
* annex.addsmallfiles: New option controlling what is done when
|
||||||
|
|
|
@ -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.
|
||||||
|
"""]]
|
Loading…
Add table
Add a link
Reference in a new issue