From cbde302536d896c69f144f1bb7e004be12273375 Mon Sep 17 00:00:00 2001 From: mbays Date: Mon, 3 Jul 2023 00:00:00 +0000 Subject: [PATCH] don't rewrite log at end if nothing appended --- ClientState.hs | 3 ++- LineClient.hs | 3 ++- ResolveTarget.hs | 2 +- diohsc.hs | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ClientState.hs b/ClientState.hs index cd22dc0..33db677 100644 --- a/ClientState.hs +++ b/ClientState.hs @@ -47,6 +47,7 @@ data ClientState = ClientState { clientCurrent :: Maybe HistoryItem , clientJumpBack :: Maybe HistoryItem , clientLog :: BStack.BStack T.Text + , clientLogTouched :: Bool , clientVisited :: S.Set Int , clientQueues :: QueueMap , clientActiveIdentities :: ActiveIdentities @@ -61,7 +62,7 @@ type ClientM = StateT ClientState IO type CommandAction = HistoryItem -> ClientM () emptyClientState :: ClientState -emptyClientState = ClientState Nothing Nothing BStack.empty S.empty M.empty M.empty emptyMarks M.empty defaultAliases defaultClientConfig +emptyClientState = ClientState Nothing Nothing BStack.empty False S.empty M.empty M.empty emptyMarks M.empty defaultAliases defaultClientConfig modifyCConf :: (ClientConfig -> ClientConfig) -> ClientM () modifyCConf f = modify $ \s -> s { clientConfig = f $ clientConfig s } diff --git a/LineClient.hs b/LineClient.hs index 8888a1d..f29db04 100644 --- a/LineClient.hs +++ b/LineClient.hs @@ -207,7 +207,7 @@ handleLine cOpts@ClientOptions{ cOptAnsi = ansi } s line = handle backupHandler handleCommandLine :: ClientOptions -> ClientState -> Bool -> CommandLine -> ClientM () handleCommandLine cOpts@(ClientOptions userDataDir interactive ansi ghost restrictedMode requestContext logH) - cState@(ClientState curr jumpBack cLog visited queues _ marks sessionMarks aliases + cState@(ClientState curr jumpBack cLog _ visited queues _ marks sessionMarks aliases (ClientConfig defaultAction proxies geminators renderFilter preOpt linkDescFirst maxLogLen maxWrapWidth confNoConfirm verboseConnection)) blockGo = \(CommandLine mt mcas) -> case mcas of @@ -310,6 +310,7 @@ handleCommandLine let t = T.pack $ show uri modify $ \s -> s { clientLog = BStack.push maxLogLen t $ clientLog s + , clientLogTouched = True , clientVisited = S.insert (hash . T.pack $ show uri) $ clientVisited s } unless ghost . liftIO $ maybe (return ()) (ignoreIOErr . (`T.hPutStrLn` t)) logH diff --git a/ResolveTarget.hs b/ResolveTarget.hs index ec38a5f..393d457 100644 --- a/ResolveTarget.hs +++ b/ResolveTarget.hs @@ -34,7 +34,7 @@ import URI import Util (maybeToEither) resolveTarget :: ClientState -> PTarget -> Either String [Target] -resolveTarget (ClientState curr jumpBack cLog visited queues _ marks sessionMarks _ _) = +resolveTarget (ClientState curr jumpBack cLog _ visited queues _ marks sessionMarks _ _) = resolveTarget' where resolveTarget' PTargetCurr = diff --git a/diohsc.hs b/diohsc.hs index f32b7cf..84af0c2 100644 --- a/diohsc.hs +++ b/diohsc.hs @@ -132,4 +132,5 @@ main = do closeLog logH -- |reread file rather than just writing clientLog, in case another instance has also -- been appending to the log. - unless ghost . warnIOErr $ truncateToEnd (clientConfMaxLogLen $ clientConfig endState) logPath + unless ghost . when (clientLogTouched endState) . warnIOErr $ + truncateToEnd (clientConfMaxLogLen $ clientConfig endState) logPath -- 2.11.4.GIT