From 6a9a9bd5a316f143964574e5ed12eb69b1d17c41 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 31 Oct 2010 01:51:50 -0400 Subject: another memory optimisation This time memory leaked if lots of UUIDs needed to be pretty-printed, as in a get or drop of many files. Essentially the same strict read buffering problem that affected the LocationLog underneath though. uuidMap really could stand to be cached, as the uuid log is read many times in this case. But it is a fairly edge case. --- UUID.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'UUID.hs') diff --git a/UUID.hs b/UUID.hs index f2235e4b6..20f85bae1 100644 --- a/UUID.hs +++ b/UUID.hs @@ -26,6 +26,7 @@ import System.Cmd.Utils import System.IO import System.Directory import qualified Data.Map as M +import System.Posix.Process import qualified GitRepo as Git import Types @@ -111,8 +112,11 @@ describeUUID uuid desc = do m <- uuidMap let m' = M.insert uuid desc m log <- uuidLog + pid <- liftIO $ getProcessID + let tmplog = log ++ ".tmp" ++ show pid liftIO $ createDirectoryIfMissing True (parentDir log) - liftIO $ withFileLocked log WriteMode (\h -> hPutStr h $ serialize m') + liftIO $ writeFile tmplog $ serialize m' + liftIO $ renameFile tmplog log where serialize m = unlines $ map (\(u, d) -> u++" "++d) $ M.toList m @@ -120,9 +124,7 @@ describeUUID uuid desc = do uuidMap :: Annex (M.Map UUID String) uuidMap = do log <- uuidLog - s <- liftIO $ catch - (withFileLocked log ReadMode $ \h -> hGetContentsStrict h) - (\error -> return "") + s <- liftIO $ catch (readFile log) (\error -> return "") return $ M.fromList $ map (\l -> pair l) $ lines s where pair l = -- cgit v1.2.3