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

@ -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