minor optimisation
authorJoey Hess <joeyh@joeyh.name>
Mon, 18 Jul 2022 17:49:17 +0000 (13:49 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 18 Jul 2022 17:50:35 +0000 (13:50 -0400)
Avoid re-writing the file when the journal directory did not
exist.

Annex/Journal.hs

index a02eaa3155e9fd3add71c609df3e0405912a5b48..2dee2b5ea2fa9970651e464ff218e2d0b7c16080 100644 (file)
@@ -84,13 +84,12 @@ setJournalFile _jl ru file content = withOtherTmp $ \tmp -> do
        -- 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))
 
 data JournalledContent
        = NoJournalledContent