From 1b6234ef0a1bdb6751a36c29a84b6e6f688fc8c0 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Wed, 16 Oct 2024 08:38:01 +0530 Subject: [PATCH] Replace "Array Word8" in the Event module with "Path" in Windows --- .../Internal/FileSystem/Event/Windows.hs | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/Streamly/Internal/FileSystem/Event/Windows.hs b/src/Streamly/Internal/FileSystem/Event/Windows.hs index c9ea2a1195..e6447fb92d 100644 --- a/src/Streamly/Internal/FileSystem/Event/Windows.hs +++ b/src/Streamly/Internal/FileSystem/Event/Windows.hs @@ -120,15 +120,13 @@ import System.Win32.Types (BOOL, DWORD, HANDLE, LPVOID, LPDWORD, failIfFalse_) import Streamly.Data.Array (Array) import Streamly.Data.Stream (Stream) import Streamly.Data.Stream.Prelude (eager) +import Streamly.Internal.FileSystem.Path (Path) import qualified Data.List.NonEmpty as NonEmpty -import qualified Streamly.Data.Array as A (fromList) import qualified Streamly.Data.Fold as Fold import qualified Streamly.Data.Stream as S import qualified Streamly.Data.Stream.Prelude as S -import qualified Streamly.Unicode.Stream as U -import qualified Streamly.Internal.Unicode.Utf8 as UTF8 (pack, toArray) -import qualified Streamly.Internal.Data.Array as A (read) +import qualified Streamly.Internal.FileSystem.Path as Path -- | Watch configuration, used to specify the events of interest and the -- behavior of the watch. @@ -428,12 +426,6 @@ pathsToHandles paths cfg = do -- Utilities ------------------------------------------------------------------------------- -utf8ToString :: Array Word8 -> FilePath -utf8ToString = runIdentity . S.fold Fold.toList . U.decodeUtf8 . A.read - -utf8ToStringList :: NonEmpty (Array Word8) -> NonEmpty FilePath -utf8ToStringList = NonEmpty.map utf8ToString - -- | Close a Directory handle. -- closePathHandleStream :: Stream IO (HANDLE, FilePath, Config) -> IO () @@ -472,13 +464,16 @@ closePathHandleStream = -- -- /Pre-release/ -- -watchWith :: (Config -> Config) -> NonEmpty (Array Word8) -> Stream IO Event +watchWith :: (Config -> Config) -> NonEmpty Path -> Stream IO Event watchWith f paths = S.bracketIO before after (S.parConcatMap (eager True) eventStreamAggr) where - before = return $ pathsToHandles (utf8ToStringList paths) $ f defaultConfig + before = + return + $ pathsToHandles (NonEmpty.map Path.toString paths) + $ f defaultConfig after = closePathHandleStream -- | Same as 'watchWith' using 'defaultConfig' and recursive mode. @@ -487,7 +482,7 @@ watchWith f paths = -- -- /Pre-release/ -- -watchRecursive :: NonEmpty (Array Word8) -> Stream IO Event +watchRecursive :: NonEmpty Path -> Stream IO Event watchRecursive = watchWith (setRecursiveMode True) -- | Same as 'watchWith' using defaultConfig and non-recursive mode. @@ -496,30 +491,26 @@ watchRecursive = watchWith (setRecursiveMode True) -- -- /Pre-release/ -- -watch :: NonEmpty (Array Word8) -> Stream IO Event +watch :: NonEmpty Path -> Stream IO Event watch = watchWith id getFlag :: DWORD -> Event -> Bool getFlag mask Event{..} = eventFlags == mask --- XXX Change the type to Array Word8 to make it compatible with other APIs. --- -- | Get the file system object path for which the event is generated, relative --- to the watched root. The path is a UTF-8 encoded array of bytes. +-- to the watched root. -- -- /Pre-release/ -- -getRelPath :: Event -> Array Word8 -getRelPath Event{..} = (UTF8.toArray . UTF8.pack) eventRelPath +getRelPath :: Event -> Path +getRelPath Event{..} = Path.fromString eventRelPath --- XXX Change the type to Array Word8 to make it compatible with other APIs. --- -- | Get the watch root directory to which this event belongs. -- -- /Pre-release/ -- -getRoot :: Event -> Array Word8 -getRoot Event{..} = (UTF8.toArray . UTF8.pack) eventRootPath +getRoot :: Event -> Path +getRoot Event{..} = Path.fromString eventRootPath -- | Get the absolute file system object path for which the event is generated. -- @@ -528,9 +519,8 @@ getRoot Event{..} = (UTF8.toArray . UTF8.pack) eventRootPath -- -- /Pre-release/ -- -getAbsPath :: Event -> Array Word8 -getAbsPath ev = getRoot ev <> backSlash <> getRelPath ev - where backSlash = A.fromList [ fromIntegral (ord '\\') ] +getAbsPath :: Event -> Path +getAbsPath ev = Path.append (getRoot ev) (getRelPath ev) -- XXX need to document the exact semantics of these. -- @@ -625,9 +615,9 @@ isEventsLost Event{..} = totalBytes == 0 showEvent :: Event -> String showEvent ev@Event{..} = "--------------------------" - ++ "\nRoot = " ++ utf8ToString (getRoot ev) - ++ "\nPath = " ++ utf8ToString (getRelPath ev) - ++ "\ngetAbsPath = " ++ utf8ToString (getAbsPath ev) + ++ "\nRoot = " ++ Path.toString (getRoot ev) + ++ "\nPath = " ++ Path.toString (getRelPath ev) + ++ "\ngetAbsPath = " ++ Path.toString (getAbsPath ev) ++ "\nFlags " ++ show eventFlags ++ showev isEventsLost "Overflow" ++ showev isCreated "Created"