Skip to content

Commit

Permalink
Rename getDirectoryContentsA to listDirectory
Browse files Browse the repository at this point in the history
Rationale:

  - Name is shorter and more familiar (most users don't need
    getDirectoryContents).
  - The 'A' suffix doesn't really fit within the existing conventions,
    nor is it clear what it means.
  • Loading branch information
Rufflewind committed Oct 11, 2015
1 parent 02b1f45 commit 91062ae
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions System/Directory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module System.Directory
, removeDirectory
, removeDirectoryRecursive
, renameDirectory
, getDirectoryContentsA
, listDirectory
, getDirectoryContents
-- ** Current working directory
, getCurrentDirectory
Expand Down Expand Up @@ -572,7 +572,7 @@ removePathRecursive path =
removeContentsRecursive :: FilePath -> IO ()
removeContentsRecursive path =
(`ioeSetLocation` "removeContentsRecursive") `modifyIOError` do
cont <- getDirectoryContentsA path
cont <- listDirectory path
mapM_ removePathRecursive [path </> x | x <- cont]
removeDirectory path

Expand Down Expand Up @@ -964,7 +964,7 @@ findFilesWith f (d:ds) fileName = do
else findFilesWith f ds fileName

#ifdef __GLASGOW_HASKELL__
-- | Similar to 'getDirectoryContentsA', but always includes the special entries (@.@
-- | Similar to 'listDirectory', but always includes the special entries (@.@
-- and @..@). (This applies to Windows as well.)
getDirectoryContents :: FilePath -> IO [FilePath]
getDirectoryContents path =
Expand Down Expand Up @@ -1002,7 +1002,7 @@ getDirectoryContents path =
-- no need to reverse, ordering is undefined
#endif /* mingw32 */

-- | @'getDirectoryContentsA' dir@ returns a list of /all/ entries in /dir/ without
-- | @'listDirectory' dir@ returns a list of /all/ entries in /dir/ without
-- the special entries (@.@ and @..@).
--
-- The operation may fail with:
Expand Down Expand Up @@ -1033,8 +1033,8 @@ getDirectoryContents path =
--
-- @since 1.2.5.0
--
getDirectoryContentsA :: FilePath -> IO [FilePath]
getDirectoryContentsA path =
listDirectory :: FilePath -> IO [FilePath]
listDirectory path =
(filter f) <$> (getDirectoryContents path)
where f filename = filename /= "." && filename /= ".."

Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Changelog for the [`directory`][1] package

## 1.2.5.0 (October 2015)

* Add `getDirectoryContentsA`, which leaves out `.` and `..`
* Add `listDirectory`, which is similar to `getDirectoryContents` but leaves
out `.` and `..`
([#36](https://github.com/haskell/directory/pull/36))

## 1.2.4.0 (September 2015)
Expand Down
4 changes: 2 additions & 2 deletions tests/CopyFile001.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ main :: TestEnv -> IO ()
main _t = do
createDirectory dir
writeFile (dir </> from) contents
T(expectEq) () [from] . sort =<< getDirectoryContentsA dir
T(expectEq) () [from] . sort =<< listDirectory dir
copyFile (dir </> from) (dir </> to)
T(expectEq) () [from, to] . sort =<< getDirectoryContentsA dir
T(expectEq) () [from, to] . sort =<< listDirectory dir
T(expectEq) () contents =<< readFile (dir </> to)
where
contents = "This is the data\n"
Expand Down
4 changes: 2 additions & 2 deletions tests/CopyFile002.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ main _t = do
-- Similar to CopyFile001 but moves a file in the current directory
-- (Bug #1652 on GHC Trac)
writeFile from contents
T(expectEq) () [from] . sort =<< getDirectoryContentsA "."
T(expectEq) () [from] . sort =<< listDirectory "."
copyFile from to
T(expectEq) () [from, to] . sort =<< getDirectoryContentsA "."
T(expectEq) () [from, to] . sort =<< listDirectory "."
T(expectEq) () contents =<< readFile to
where
contents = "This is the data\n"
Expand Down
4 changes: 2 additions & 2 deletions tests/GetDirContents001.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ main :: TestEnv -> IO ()
main _t = do
createDirectory dir
T(expectEq) () specials . sort =<< getDirectoryContents dir
T(expectEq) () [] . sort =<< getDirectoryContentsA dir
T(expectEq) () [] . sort =<< listDirectory dir
names <- for [1 .. 100 :: Int] $ \ i -> do
let name = 'f' : show i
writeFile (dir </> name) ""
return name
T(expectEq) () (sort (specials <> names)) . sort =<< getDirectoryContents dir
T(expectEq) () (sort names) . sort =<< getDirectoryContentsA dir
T(expectEq) () (sort names) . sort =<< listDirectory dir
where dir = "dir"
specials = [".", ".."]
2 changes: 1 addition & 1 deletion tests/TestUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ copyPathRecursive source dest =
dirExists <- doesDirectoryExist source
if dirExists
then do
contents <- getDirectoryContentsA source
contents <- listDirectory source
createDirectory dest
mapM_ (uncurry copyPathRecursive)
[(source </> x, dest </> x) | x <- contents]
Expand Down
4 changes: 2 additions & 2 deletions tests/WithCurrentDirectory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ main :: TestEnv -> IO ()
main _t = do
createDirectory dir
-- Make sure we're starting empty
T(expectEq) () [] . sort =<< getDirectoryContentsA dir
T(expectEq) () [] . sort =<< listDirectory dir
cwd <- getCurrentDirectory
withCurrentDirectory dir (writeFile testfile contents)
-- Are we still in original directory?
T(expectEq) () cwd =<< getCurrentDirectory
-- Did the test file get created?
T(expectEq) () [testfile] . sort =<< getDirectoryContentsA dir
T(expectEq) () [testfile] . sort =<< listDirectory dir
-- Does the file contain what we expected to write?
T(expectEq) () contents =<< readFile (dir </> testfile)
where
Expand Down

0 comments on commit 91062ae

Please sign in to comment.