From fd20a9c8613533838f5d5d398cf2d31496b99b94 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Sun, 31 Jan 2021 21:05:37 +0000 Subject: [PATCH] Atomic writeStateToFile --- src/XMonad/Operations.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/XMonad/Operations.hs b/src/XMonad/Operations.hs index fedb7192..3c08a676 100644 --- a/src/XMonad/Operations.hs +++ b/src/XMonad/Operations.hs @@ -79,6 +79,7 @@ import qualified Control.Exception as C import System.IO import System.Directory +import System.FilePath ((<.>)) import System.Posix.Process (executeFile) import Graphics.X11.Xlib import Graphics.X11.Xinerama (getScreenInfo) @@ -663,7 +664,9 @@ writeStateToFile = do globalPath <- asks $ stateFileName . directories path <- fromMaybe globalPath <$> sessionStateFileName stateData <- gets (\s -> StateFile (wsData s) (extState s)) - catchIO (writeFile path $ show stateData) + catchIO $ do + writeFile (path <.> "tmp") $ show stateData + renameFile (path <.> "tmp") path -- | Read the state of a previous xmonad instance from a file and -- return that state. The state file is removed after reading it.