From 133584a83ad2765bd6df1a5d84d01f86a25c67f1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 30 Aug 2024 11:58:10 -0400 Subject: [PATCH] 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. --- Annex/RepoSize.hs | 11 +++++++++-- Database/RepoSize.hs | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Annex/RepoSize.hs b/Annex/RepoSize.hs index 680a6e897b..5bd089299d 100644 --- a/Annex/RepoSize.hs +++ b/Annex/RepoSize.hs @@ -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 diff --git a/Database/RepoSize.hs b/Database/RepoSize.hs index 73a1d06700..20de270442 100644 --- a/Database/RepoSize.hs +++ b/Database/RepoSize.hs @@ -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