packages feed

dir-traverse (empty) → 0.1.0.0

raw patch · 6 files changed

+134/−0 lines, 6 filesdep +basedep +composition-preludedep +criterion

Dependencies added: base, composition-prelude, criterion, dir-traverse, directory, dirstream, dlist, filepath, pipes, pipes-safe, system-filepath

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# dir-traverse++## 0.1.0.0++Initial release
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright Vanessa McHale (c) 2019++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,5 @@+# dir-traverse++Get all descendants of a directory. It should have similar performance to+[dirstream](http://hackage.haskell.org/package/dirstream), with fewer+dependencies.
+ bench/Bench.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE OverloadedStrings #-}++module Main (main) where++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.Recursive++dirstreamGet :: F.FilePath -> IO ()+dirstreamGet fp =+    runSafeT $ runEffect $+        for (every (descendentOf fp)) (liftIO . (\x -> pure $ x `seq` ()))++discard :: Functor f => f a -> f ()+discard = fmap (\x -> x `seq` ())++main :: IO ()+main =+    defaultMain [ bgroup "."+                      [ bench "getDirRecursive" $ nfIO (discard <$> getDirRecursive ".")+                      , bench "DirStream" $ nfIO (dirstreamGet ".")+                      ]+                ]
+ dir-traverse.cabal view
@@ -0,0 +1,61 @@+cabal-version: 1.18+name: dir-traverse+version: 0.1.0.0+license: BSD3+license-file: LICENSE+copyright: Copyright: (c) 2019 Vanessa McHale+maintainer: vanessa.mchale@iohk.io+author: Vanessa McHale+synopsis: Simple directory traversal library+description:+    Simple cross-platform directory traversals in Haskell+category: System, Directory+build-type: Simple+extra-doc-files: README.md+                 CHANGELOG.md++source-repository head+    type: git+    location: https://github.com/vmchale/dir-traverse++library+    exposed-modules:+        System.Directory.Recursive+    hs-source-dirs: src+    default-language: Haskell2010+    ghc-options: -Wall -O2+    build-depends:+        base >=4.5 && <5,+        dlist -any,+        directory >=1.2.5.0,+        composition-prelude -any,+        filepath -any++    if impl(ghc >=8.0)+        ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates+                     -Wredundant-constraints -Widentities++    if impl(ghc >=8.4)+        ghc-options: -Wmissing-export-lists++benchmark dir-traverse-bench+    type: exitcode-stdio-1.0+    main-is: Bench.hs+    hs-source-dirs: bench+    default-language: Haskell2010+    ghc-options: -Wall+    build-depends:+        base >=4.8,+        dir-traverse -any,+        criterion -any,+        dirstream -any,+        pipes -any,+        pipes-safe -any,+        system-filepath -any++    if impl(ghc >=8.0)+        ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates+                     -Wredundant-constraints -Widentities++    if impl(ghc >=8.4)+        ghc-options: -Wmissing-export-lists
+ src/System/Directory/Recursive.hs view
@@ -0,0 +1,25 @@+module System.Directory.Recursive ( getDirRecursive ) where++import           Control.Applicative (pure, (<$>))+import           Control.Composition ((.*))+import           Control.Monad       (filterM)+import qualified Data.DList          as DL+import           Data.Foldable       (fold)+import           Data.Traversable    (traverse)+import           System.Directory    (doesDirectoryExist, listDirectory)+import           System.FilePath     ((</>))++{-# INLINE getDirRecursive #-}+getDirRecursive :: FilePath -> IO (DL.DList FilePath)+getDirRecursive fp = do+    all' <- listDirectory fp+    let all'' = mkRel <$> all'+    dirs <- filterM doesDirectoryExist all''+    case dirs of+        [] -> pure $ DL.fromList all''+        ds -> do+            next <- foldMapA getDirRecursive ds+            pure $ next `DL.append` DL.fromList all''++    where foldMapA = fmap fold .* traverse+          mkRel = (fp </>)