Merge branch 'master' into append
authorJoey Hess <joeyh@joeyh.name>
Mon, 18 Jul 2022 18:17:15 +0000 (14:17 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 18 Jul 2022 18:17:15 +0000 (14:17 -0400)
1  2 
Annex/Journal.hs

index d02c42355d09ab951458c1082de471dbb9da537d,2dee2b5ea2fa9970651e464ff218e2d0b7c16080..5a87d0f7e472192824819fb09c7bba99ec76dd90
@@@ -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