Skip to content

Commit

Permalink
Merge pull request #17 from snoyberg/better-getDirectoryContents
Browse files Browse the repository at this point in the history
Better get directory contents
  • Loading branch information
snoyberg committed Feb 17, 2015
2 parents b78c422 + 9393527 commit c51ade2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ install:

script:
- autoreconf -i
- cabal configure -v2
- cabal configure -v2 --enable-tests
- cabal build
- cabal check
- cabal sdist
- cabal test
# The following scriptlet checks that the resulting source distribution can be built & installed
- export SRC_TGZ=$(cabal info . | awk '{print $2 ".tar.gz";exit}') ;
cd dist/;
Expand Down
17 changes: 10 additions & 7 deletions System/Directory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ createDirectoryIfMissing create_parents path0
#else
canIgnore <- (Posix.isDirectory `fmap` Posix.getFileStatus dir)
#endif
`catch` ((\ _ -> return (isAlreadyExistsError e))
`E.catch` ((\ _ -> return (isAlreadyExistsError e))
:: IOException -> IO Bool)
unless canIgnore (throwIO e)
| otherwise -> throwIO e
Expand Down Expand Up @@ -839,13 +839,16 @@ getDirectoryContents path =
bracket
(Posix.openDirStream path)
Posix.closeDirStream
loop
start
where
loop dirp = do
e <- Posix.readDirStream dirp
if null e then return [] else do
es <- loop dirp
return (e:es)
start dirp =
loop id
where
loop acc = do
e <- Posix.readDirStream dirp
if null e
then return (acc [])
else loop (acc . (e:))
#else
bracket
(Win32.findFirstFile (path </> "*"))
Expand Down
11 changes: 10 additions & 1 deletion directory.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extra-source-files:

source-repository head
type: git
location: http://git.haskell.org/packages/directory.git
location: https://github.com/haskell/directory

Library
default-language: Haskell2010
Expand Down Expand Up @@ -61,3 +61,12 @@ Library
build-depends: unix >= 2.5.1 && < 2.8

ghc-options: -Wall

test-suite test
default-language: Haskell2010
hs-source-dirs: test
main-is: main.hs
type: exitcode-stdio-1.0
build-depends: base
, directory
, containers
20 changes: 20 additions & 0 deletions test/main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{-# LANGUAGE NoImplicitPrelude #-}
-- Simplistic test suite for now. Worthwhile to add a dependency on a
-- test framework at some point.
module Main (main) where

import qualified Data.Set as Set
import Prelude (IO, error, fmap, return, show, (==))
import System.Directory (getDirectoryContents)

main :: IO ()
main = do
let expected = Set.fromList
[ "."
, ".."
, "main.hs"
]
actual <- fmap Set.fromList (getDirectoryContents "test")
if expected == actual
then return ()
else error (show (expected, actual))

0 comments on commit c51ade2

Please sign in to comment.