Skip to content

Commit

Permalink
Atomic writeStateToFile
Browse files Browse the repository at this point in the history
  • Loading branch information
liskin committed Dec 17, 2023
1 parent 86a5761 commit cc6c9f5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/XMonad/Operations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cc6c9f5

Please sign in to comment.