From 486f14ddd149eb43e57b3e8341638cc7f1542317 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 17 Feb 2015 10:29:11 +0200 Subject: [PATCH 1/4] Fix source repository --- directory.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/directory.cabal b/directory.cabal index 69266c67..32f22a17 100644 --- a/directory.cabal +++ b/directory.cabal @@ -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 From e5ab0653643c18ec6106be1674179ae94c66e858 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 17 Feb 2015 11:29:58 +0200 Subject: [PATCH 2/4] Add fledgeling test suite We should really get this to run all of the tests in the tests directory instead. --- .travis.yml | 3 ++- directory.cabal | 9 +++++++++ test/main.hs | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/main.hs diff --git a/.travis.yml b/.travis.yml index ea01c3ce..05ed4e40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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/; diff --git a/directory.cabal b/directory.cabal index 32f22a17..83e4109f 100644 --- a/directory.cabal +++ b/directory.cabal @@ -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 diff --git a/test/main.hs b/test/main.hs new file mode 100644 index 00000000..7a9fcb3c --- /dev/null +++ b/test/main.hs @@ -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)) From 81be17f03b1a9c47c0fcd318a446a643639058d9 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 17 Feb 2015 10:32:21 +0200 Subject: [PATCH 3/4] More efficient getDirectoryContents See https://ghc.haskell.org/trac/ghc/ticket/9266 --- System/Directory.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/System/Directory.hs b/System/Directory.hs index 26600a06..29addf1e 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -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 "*")) From 9393527136c2fbac675c4afd7e1f4f3266d331da Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 17 Feb 2015 14:26:11 +0200 Subject: [PATCH 4/4] Disambiguate catch for older GHC --- System/Directory.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/System/Directory.hs b/System/Directory.hs index 29addf1e..5e77f4de 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -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