Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better get directory contents #17

Merged
merged 4 commits into from
Feb 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))