From 6d3e8d65e148e205cd5c0f8227d1d91cd04312a4 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 11 Feb 2023 18:51:34 +0800 Subject: [PATCH] Make readDirEntPortable more robust --- lib/GHCup/Prelude/File/Posix/Traversals.hsc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/GHCup/Prelude/File/Posix/Traversals.hsc b/lib/GHCup/Prelude/File/Posix/Traversals.hsc index 645ee51..5620530 100644 --- a/lib/GHCup/Prelude/File/Posix/Traversals.hsc +++ b/lib/GHCup/Prelude/File/Posix/Traversals.hsc @@ -117,7 +117,15 @@ readDirEntPortable :: DirStreamPortable -> IO (DirType, FilePath) readDirEntPortable (DirStreamPortable (basedir, dirs)) = do (dt, fp) <- readDirEnt dirs case (dt, fp) of - (DirType #{const DT_UNKNOWN}, _) + (DirType #{const DT_BLK}, _) -> pure (dt, fp) + (DirType #{const DT_CHR}, _) -> pure (dt, fp) + (DirType #{const DT_DIR}, _) -> pure (dt, fp) + (DirType #{const DT_FIFO}, _) -> pure (dt, fp) + (DirType #{const DT_LNK}, _) -> pure (dt, fp) + (DirType #{const DT_REG}, _) -> pure (dt, fp) + (DirType #{const DT_SOCK}, _) -> pure (dt, fp) + (DirType #{const DT_UNKNOWN}, _) -> pure (dt, fp) + (_, _) | fp /= "" -> do stat <- getSymbolicLinkStatus (basedir fp) pure $ (, fp) $ if | isBlockDevice stat -> DirType #{const DT_BLK} @@ -128,5 +136,4 @@ readDirEntPortable (DirStreamPortable (basedir, dirs)) = do | isRegularFile stat -> DirType #{const DT_REG} | isSocket stat -> DirType #{const DT_SOCK} | otherwise -> DirType #{const DT_UNKNOWN} - _ -> pure (dt, fp)