Skip to content

Commit

Permalink
Do not overwrite syntax.css if it is being written by another thread
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Feb 4, 2024
1 parent 542441e commit 1bc0957
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions liquidhaskell-boot/src/Language/Haskell/Liquid/UX/Annotate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import Data.Maybe (mapMaybe)
import Data.Aeson
import Control.Arrow hiding ((<+>))
-- import Control.Applicative ((<$>))
import Control.Monad (when, forM_)
import Control.Exception (catchJust)
import Control.Monad (guard, when, forM_)
import GHC.IO.Exception (IOErrorType(ResourceBusy), ioe_type)

import System.Exit (ExitCode (..))
import System.FilePath (dropFileName, (</>))
Expand Down Expand Up @@ -132,10 +134,16 @@ copyFileCreateParentDirIfMissing src tgt = do
Dir.createDirectoryIfMissing False $ tempDirectory tgt
Dir.copyFile src tgt

-- | Creates the parent directory and tries to writes the file.
-- Might not write to the file if someone else is writing to it
-- already.
writeFileCreateParentDirIfMissing :: T.Text -> FilePath -> IO ()
writeFileCreateParentDirIfMissing s tgt = do
Dir.createDirectoryIfMissing False $ tempDirectory tgt
Text.writeFile tgt s
catchJust
(\e -> guard (ioe_type e == ResourceBusy))
(Text.writeFile tgt s)
(const (return ()))

writeFilesOrStrings :: FilePath -> [Either FilePath String] -> IO ()
writeFilesOrStrings tgtFile = mapM_ $ either (`copyFileCreateParentDirIfMissing` tgtFile) (tgtFile `appendFile`)
Expand Down

0 comments on commit 1bc0957

Please sign in to comment.