From 928b2a483911a527e4741fc14d63531431f9fb7d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 21 Jun 2023 15:23:59 -0400 Subject: [PATCH] create journal directory in withJournalHandle Fixes a crash by git-annex repair when .git/annex/journal/ does not exist. Normally the journal directory is created before withJournalHandle gets run, but git-annex repair can be run in a situation where it does not exist. --- Annex/Journal.hs | 9 +++++++-- CHANGELOG | 1 + ...ex-repair_claims_success_then_failure.mdwn | 2 ++ ..._de8dfda0bc321e573ab9d17aec1ecb84._comment | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 doc/bugs/git-annex-repair_claims_success_then_failure/comment_1_de8dfda0bc321e573ab9d17aec1ecb84._comment diff --git a/Annex/Journal.hs b/Annex/Journal.hs index 48b12c0450..ea6327606d 100644 --- a/Annex/Journal.hs +++ b/Annex/Journal.hs @@ -230,8 +230,13 @@ getJournalledFilesStale getjournaldir = do {- Directory handle open on a journal directory. -} withJournalHandle :: (Git.Repo -> RawFilePath) -> (DirectoryHandle -> IO a) -> Annex a withJournalHandle getjournaldir a = do - d <- fromRawFilePath <$> fromRepo getjournaldir - bracketIO (openDirectory d) closeDirectory (liftIO . a) + d <- fromRepo getjournaldir + bracket (opendir d) (liftIO . closeDirectory) (liftIO . a) + where + -- avoid overhead of creating the journal directory when it already + -- exists + opendir d = liftIO (openDirectory (fromRawFilePath d)) + `catchIO` (const (createAnnexDirectory d >> opendir d)) {- Checks if there are changes in the journal. -} journalDirty :: (Git.Repo -> RawFilePath) -> Annex Bool diff --git a/CHANGELOG b/CHANGELOG index dd0fd952a8..4398a3e607 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -92,6 +92,7 @@ git-annex (10.20230408) UNRELEASED; urgency=medium * assistant: Fix a crash when a small file is deleted immediately after being created. * repair: Fix handling of git ref names on Windows. + * repair: Fix a crash when .git/annex/journal/ does not exist. * Support building with optparse-applicative 0.18.1 (Thanks, Peter Simons) diff --git a/doc/bugs/git-annex-repair_claims_success_then_failure.mdwn b/doc/bugs/git-annex-repair_claims_success_then_failure.mdwn index 8e2c4c29cc..e08d986593 100644 --- a/doc/bugs/git-annex-repair_claims_success_then_failure.mdwn +++ b/doc/bugs/git-annex-repair_claims_success_then_failure.mdwn @@ -48,3 +48,5 @@ I did that because annexed objects are 1.7TB big here, so I wanted a local copy I'll keep the repo lying around for a few days, maybe weeks, if some experiment or further feedback is needed. Thank you for your attention. + +> [[fixed|done]].. sorry for the delay and thanks for reporting --[[Joey]] diff --git a/doc/bugs/git-annex-repair_claims_success_then_failure/comment_1_de8dfda0bc321e573ab9d17aec1ecb84._comment b/doc/bugs/git-annex-repair_claims_success_then_failure/comment_1_de8dfda0bc321e573ab9d17aec1ecb84._comment new file mode 100644 index 0000000000..1f3c26a3b2 --- /dev/null +++ b/doc/bugs/git-annex-repair_claims_success_then_failure/comment_1_de8dfda0bc321e573ab9d17aec1ecb84._comment @@ -0,0 +1,19 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2023-06-21T18:53:31Z" + content=""" +I was able to reproduce this bug! + + git-annex init + rm -rf .git/annex + git-annex repair + + git-annex: .git/annex/journal/: openDirStream: does not exist (No such file or directory) + +That's with Annex.Repair modified to always run commitindex. Having a +repository with a git-annex branch that is corrupt, would have the same effect +as that modification. + +Fixed this. +"""]]