This commit is contained in:
Dmitry Zuikov 2024-08-02 17:35:30 +03:00
parent 71eb40c3e2
commit 7e5fa70503
1 changed files with 13 additions and 21 deletions

View File

@ -35,33 +35,27 @@ glob pat ignore dir action = do
where where
ppat = zip (repeat True) pat matches p f = or [ i ?== f | i <- p ]
spat = zip (repeat True) ignore skip p = or [ i ?== p | i <- ignore ]
go f = do go f = do
isF <- liftIO $ doesFileExist f
when isF do
liftIO $ print f
isD <- liftIO $ doesDirectoryExist f isD <- liftIO $ doesDirectoryExist f
when isD do if not isD then do
co <- liftIO (try @_ @IOError $ listDirectory f) isF <- liftIO $ doesFileExist f
when (isF && matches pat f) do
liftIO $ print f
-- do shit with file
else do
co' <- liftIO (try @_ @IOError $ listDirectory f)
<&> fromRight mempty <&> fromRight mempty
let fns = matchMany ppat [ (f </> x, x) | x <- co ] let co = [ normalise (f </> x) | x <- co' ]
let stop = matchMany spat [ (f </> x, x) | x <- co ] & filter (not . skip)
let ss = HS.fromList $ (fmap (view _2)) stop
-- matchMany :: [(a, FilePattern)] -> [(b, FilePath)] -> [(a, b, [String])] for_ co $ \p -> do
go p
liftIO $ print spat
liftIO $ print stop
-- for_ co $ \p -> do
-- liftIO $ print p
-- unless (HS.member p ss) do
-- go (f </> p)
-- q <- newTQueueIO -- q <- newTQueueIO
@ -98,8 +92,6 @@ glob pat ignore dir action = do
-- Just e -> void (action e) >> next -- Just e -> void (action e) >> next
-- where -- where
-- matches p f = or [ i ?== f | i <- p ]
-- skip p = or [ i ?== p | i <- ignore ]
entries :: forall c m . ( IsContext c entries :: forall c m . ( IsContext c
, Exception (BadFormException c) , Exception (BadFormException c)