packages feed

dir-traverse 0.2.0.1 → 0.2.1.0

raw patch · 4 files changed

+51/−12 lines, 4 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ System.Directory.Recursive: getSubdirsRecursive :: FilePath -> IO [FilePath]

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # dir-traverse +## 0.2.1.0++  * Add `getSubdirsRecursive`+ ## 0.2.0.1    * Fix performance silliness
bench/Bench.hs view
@@ -2,14 +2,18 @@  module Main (main) where +import           Control.Monad              (filterM, (<=<)) import           Control.Monad.IO.Class     (liftIO) import           Criterion.Main import           Data.DirStream import qualified Filesystem.Path            as F import           Pipes                      (every, for, runEffect) import           Pipes.Safe                 (runSafeT)+import           System.Directory           (doesDirectoryExist) import           System.Directory.Recursive ++-- todo use http://hackage.haskell.org/package/pipes-4.3.9/docs/Pipes-Prelude.html#v:toListM dirstreamGet :: F.FilePath -> IO () dirstreamGet fp =     runSafeT $ runEffect $@@ -18,10 +22,17 @@ discard :: Functor f => f a -> f () discard = fmap (\x -> x `seq` ()) +filtered :: FilePath -> IO [FilePath]+filtered = filterM doesDirectoryExist <=< getDirRecursive+ main :: IO () main =     defaultMain [ bgroup "."                       [ bench "getDirRecursive" $ nfIO (discard <$> getDirRecursive ".")                       , bench "DirStream" $ nfIO (dirstreamGet ".")+                      ]+                , bgroup "dirs"+                      [ bench "getSubdirsRecursive" $ nfIO (discard <$> getSubdirsRecursive ".")+                      , bench "filterM doesDirectoryExist <=< getDirRecursive" $ nfIO (discard <$> filtered ".")                       ]                 ]
dir-traverse.cabal view
@@ -1,10 +1,10 @@ cabal-version: 1.18 name: dir-traverse-version: 0.2.0.1+version: 0.2.1.0 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2019 Vanessa McHale-maintainer: vanessa.mchale@iohk.io+maintainer: vamchale@gmail.com author: Vanessa McHale synopsis: Simple directory traversal library description:@@ -42,13 +42,14 @@     default-language: Haskell2010     ghc-options: -Wall     build-depends:-        base >=4.8,+        base >=4.9,         dir-traverse -any,         criterion -any,         dirstream -any,         pipes -any,         pipes-safe -any,-        system-filepath -any+        system-filepath -any,+        directory -any      if impl(ghc >=8.0)         ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates
src/System/Directory/Recursive.hs view
@@ -1,4 +1,6 @@-module System.Directory.Recursive ( getDirRecursive ) where+module System.Directory.Recursive ( getDirRecursive+                                  , getSubdirsRecursive+                                  ) where  import           Control.Applicative (pure, (<$>)) import           Control.Monad       (filterM)@@ -7,6 +9,23 @@ import           System.Directory    (doesDirectoryExist, getDirectoryContents) import           System.Info         (os) ++{-# INLINE getSubdirsRecursive #-}+-- | @since 0.2.1.0+getSubdirsRecursive :: FilePath -> IO [FilePath]+getSubdirsRecursive fp = do+    all' <- listDirectory fp+    let all'' = mkRel <$> all'+    dirs <- filterM doesDirectoryExist all''+    case dirs of+        [] -> pure dirs+        ds -> do+            next <- foldMapA getSubdirsRecursive ds+            pure $ dirs ++ next++    where mkRel = (fp </>)+          foldMapA = (fmap fold .) . traverse+ {-# INLINE getDirRecursive #-} getDirRecursive :: FilePath -> IO [FilePath] getDirRecursive fp = do@@ -19,10 +38,14 @@             next <- foldMapA getDirRecursive ds             pure $ all'' ++ next -    where foldMapA = (fmap fold .) . traverse-          mkRel = (fp </>)-          (</>) x y =-            case os of-                "mingw32" -> x ++ "\\" ++ y-                _         -> x ++ "/" ++ y-          listDirectory = fmap (filter (\p -> p /= "." && p /= "..")) . getDirectoryContents+    where mkRel = (fp </>)+          foldMapA = (fmap fold .) . traverse++(</>) :: FilePath -> FilePath -> FilePath+(</>) x y =+    case os of+        "mingw32" -> x ++ "\\" ++ y+        _         -> x ++ "/" ++ y++listDirectory :: FilePath -> IO [FilePath]+listDirectory = fmap (filter (\p -> p /= "." && p /= "..")) . getDirectoryContents