[ ghc-Bugs-570985 ] doesDirectoryExist doesnt work right

noreply at sourceforge.net noreply at sourceforge.net
Thu Jun 20 08:32:54 EDT 2002


Bugs item #570985, was opened at 2002-06-19 06:01
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=570985&group_id=8032

Category: Compiler
Group: 5.02
>Status: Closed
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: doesDirectoryExist doesnt work right

Initial Comment:
doesDirectoryExist and doesFileExist work on the
toplevel for ghci but they dont work in my code. for
example

Prelude> :l Sorter.hs 
Compiling Sorter           ( Sorter.hs, interpreted )
Ok, modules loaded: Sorter.
Sorter> doesDirectoryExist "/usr/include"
it :: Bool
Sorter> print it
True
it :: ()

this works fine.

now the relevant part of my code is

module Test ()
where

import Directory

foldrIO f s [] = do return s
foldrIO f s (x:xs) = do
        p <- foldrIO f s xs
        f x p

filterIO :: (a -> IO Bool) -> [a] -> IO [a]
filterIO p l = do
        foldrIO (\x xs -> do
                s <- p x
                return (if s then x:xs else xs))
                [] l

isDir = doesDirectoryExist

getDirs dir = do
        d <- getDirectoryContents dir
        p <- filterIO isDir d
        return (filter (/= ".") (filter (/= "..") p))

and what happens is

Sorter> :l Test.hs    -- test contains only the code i
gave above
Compiling Test             ( Test.hs, interpreted )
Ok, modules loaded: Test.
Test> getDirs "/usr"
it :: [[Char]]
Test> print it
["bin","src"]
it :: ()
Test> getDirectoryContents "/usr"
it :: [FilePath]
Test> print it
[".","..","bin","include","lib","libdata","libexec","local","sbin","share","src","games","ports","X11R6","compat","obj","tmp","home","var","sup"]
it :: ()
Test> doesDirectoryExist "/usr/include"
it :: Bool
Test> print it
True
it :: ()
Test> doesDirectoryExist "/usr/libexec"
it :: Bool
Test> print it
True
it :: ()
Test> doesDirectoryExist "/usr/src"
it :: Bool
Test> print it
True
it :: ()

in the /usr dir only src and bin get recognized as dirs
even though everyone of the files in /usr is a dir. in
many dirs none of the subdirs are recognized. so far it
has consistently been recognizing the same subdirs in
each dir i test but i dont know if that means anything.
if you test each of them with doesDirectoryExist on the
toplevel of ghci each of them is recognized as a dir.

this problem also shows up if i compile it.

an analgous problem exists for doesFileExist.

i run freebsd 4.5 stable with ghc 5.02.2. if there is
anything i can do to help you fix this please let me
know at uglydaemon at shaw.ca

----------------------------------------------------------------------

>Comment By: Simon Marlow (simonmar)
Date: 2002-06-20 12:32

Message:
Logged In: YES 
user_id=48280

There is a bug in your program: getDirs is calling 
doesDirectoryExist on names returned by 
getDirectoryContents, relative to the *current* directory, not 
the directory you originally asked for the contents of.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=570985&group_id=8032



More information about the Glasgow-haskell-bugs mailing list