From: Joey Hess Date: Mon, 18 Jul 2022 18:17:15 +0000 (-0400) Subject: Merge branch 'master' into append X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~72^2~22^2~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ccff6396518e4e117783c21afcf0dc00a5ec30f1;p=git-annex.git Merge branch 'master' into append --- ccff6396518e4e117783c21afcf0dc00a5ec30f1 diff --cc Annex/Journal.hs index d02c42355d,2dee2b5ea2..5a87d0f7e4 --- a/Annex/Journal.hs +++ b/Annex/Journal.hs @@@ -84,37 -84,13 +84,36 @@@ setJournalFile _jl ru file content = wi -- journal file is written atomically let jfile = journalFile file let tmpfile = tmp P. jfile - let write = liftIO $ do - withFile (fromRawFilePath tmpfile) WriteMode $ \h -> - writeJournalHandle h content - moveFile tmpfile (jd P. jfile) + liftIO $ withFile (fromRawFilePath tmpfile) WriteMode $ \h -> + writeJournalHandle h content + let mv = liftIO $ moveFile tmpfile (jd P. jfile) -- avoid overhead of creating the journal directory when it already -- exists - write `catchIO` (const (createAnnexDirectory jd >> write)) + mv `catchIO` (const (createAnnexDirectory jd >> mv)) +{- Appends content to a journal file. + - + - The oldcontent is whatever is in the git-annex branch. + - When the journal file does not yet exist, the oldcontent + - is first written to the journal file. + - + - TODO: Unsafe! Does not append atomically. -} +appendJournalFile :: Journalable content => JournalLocked -> RegardingUUID -> RawFilePath -> L.ByteString -> content -> Annex () +appendJournalFile _jl ru file oldcontent toappend = do + jd <- fromRepo =<< ifM (regardingPrivateUUID ru) + ( return gitAnnexPrivateJournalDir + , return gitAnnexJournalDir + ) + let jfile = fromRawFilePath $ jd P. journalFile file + let write = liftIO $ ifM (doesFileExist jfile) + ( withFile jfile AppendMode $ \h -> + writeJournalHandle h toappend + , withFile jfile WriteMode $ \h -> do + writeJournalHandle h oldcontent + writeJournalHandle h toappend + ) + write `catchIO` (const (createAnnexDirectory jd >> write)) + data JournalledContent = NoJournalledContent | JournalledContent L.ByteString