From 37a239308d247bc9debb226bbe5b7ab8d7fd954e Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 8 Dec 2025 00:36:48 -0700 Subject: [bugfix] - fix missing interface file race condition. --- src/Language/Fiddle/Compiler/ImportResolution.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Language/Fiddle/Compiler/ImportResolution.hs b/src/Language/Fiddle/Compiler/ImportResolution.hs index 5c09523..296b540 100644 --- a/src/Language/Fiddle/Compiler/ImportResolution.hs +++ b/src/Language/Fiddle/Compiler/ImportResolution.hs @@ -10,9 +10,10 @@ where import qualified Codec.Compression.GZip as GZip import Control.Arrow (Arrow (second)) +import Control.Exception (uninterruptibleMask) import Control.Monad (filterM, when) -import Control.Monad.State (put) import Control.Monad.Loops (untilM_) +import Control.Monad.State (put) import Control.Monad.Trans.Maybe (MaybeT (MaybeT, runMaybeT)) import Control.Monad.Writer.Lazy (MonadTrans (lift), MonadWriter (tell), WriterT (..), execWriterT) import Data.Aeson (eitherDecode, encode) @@ -31,8 +32,8 @@ import Language.Fiddle.Types import Options.Applicative import System.Directory import System.FilePath +import System.IO.Error (catchIOError) import Text.Printf (printf) -import Control.Exception (uninterruptibleMask) data Flags = Flags { importDirectories :: [FilePath], @@ -278,7 +279,12 @@ getImportResolutionState parseFile compileToChecked flags unit = do untilM_ (return ()) (doesFileExist intfile) else do BL.writeFile tmpIntFile $ GZip.compress (encode val) - renameFile tmpIntFile intfile + + -- Might get a "file does not exist", means another process already + -- moved it. + catchIOError + (renameFile tmpIntFile intfile) + (\(e :: IOError) -> return ()) interfaceFileValid :: FilePath -> FilePath -> IO Bool interfaceFileValid originalPath intfPath = do -- cgit