avoid locking the journal in readonly repository

The test suite flagged that git-annex info in a readonly repository was
no longer working.

.git/annex/journal.lck: openFd: permission denied

This fixes it, however, in a case where .git/annex/reposize/ is
writable, but .git/annex/journal/ is not, there will still be a
permission denied error. The solution would just be to use consistent
permissions I suppose.
This commit is contained in:
Joey Hess 2024-08-30 11:58:10 -04:00
parent 53b7375cc6
commit 133584a83a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 17 additions and 2 deletions

View file

@ -138,11 +138,18 @@ calcJournalledRepoSizes
-> M.Map UUID RepoSize
-> Sha
-> Annex (M.Map UUID (RepoSize, SizeOffset))
calcJournalledRepoSizes h startmap branchsha =
calcJournalledRepoSizes h startmap branchsha
-- Lock the journal to prevent updates to the size offsets
-- in the repository size database while this is processing
-- the journal files.
lockJournal $ \_jl -> do
| Db.isOpenDb h = lockJournal $ \_jl -> go
-- When the repository is not writable, the database won't have
-- been opened, and locking the journal would also not succeed.
-- But there is no need to lock the journal in this case,
-- since no offsets will be read from the database.
| otherwise = go
where
go = do
sizemap <- overLocationLogsJournal startmap branchsha
(\k v m' -> pure (accumRepoSizes k v m'))
Nothing

View file

@ -23,6 +23,7 @@ module Database.RepoSize (
getRepoSizeHandle,
openDb,
closeDb,
isOpenDb,
lockDbWhile,
getRepoSizes,
setRepoSizes,
@ -126,6 +127,13 @@ openDb = lockDbWhile permerr $ do
-- efficiently.
permerr _e = mkhandle Nothing
-- When the repository cannot be written to, openDb returns a
-- RepoSizeHandle that is not actually open, all operations on it will do
-- nothing.
isOpenDb :: RepoSizeHandle -> Bool
isOpenDb (RepoSizeHandle (Just _) _) = True
isOpenDb (RepoSizeHandle Nothing _) = False
closeDb :: RepoSizeHandle -> Annex ()
closeDb (RepoSizeHandle (Just h) _) = liftIO $ H.closeDb h
closeDb (RepoSizeHandle Nothing _) = noop