System.Posix.Files.isDirectory and System.Posix.Files.isSymbolicLink

Hi all, The following code creates a symbolic link in the current directory and then uses System.Posix.Files.getFileStatus to get the status of the link. However, isDirectory returns True and isSymbolicLink returns False which is very different from what the stat() system call on a POSIX system would return. I consider this a bug. I'm using ghc-6.8.2. Has this been fixed in a later version? Cheers, Erik module Main where import qualified System.Directory import qualified System.Posix.Files main :: IO () main = do let linkName = "tmp-link" cwd <- System.Directory.getCurrentDirectory System.Posix.Files.createSymbolicLink "/tmp" linkName stat <- System.Posix.Files.getFileStatus linkName if System.Posix.Files.isDirectory stat then putStrLn "Is a directory?????" else putStrLn "Not a directory." if System.Posix.Files.isSymbolicLink stat then putStrLn "Is a symlink" else putStrLn "Not a symlink?????" -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." - John Von Neumann (1951)

Erik de Castro Lopo wrote:
The following code creates a symbolic link in the current directory and then uses System.Posix.Files.getFileStatus to get the status of the link.
If I use getSymbolicLinkStatus instead of getFileStatus I get the result I expect. However, using getSymbolicLinkStatus instead of getFileStatus is highly counter-intuitive. Furthermore System.Directory.doesDirectoryExist seems to use getFileStatus so that if one tries to walk a directory tree one will also follow symlinks and if those links are circular you get an infinite loop. Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- Christianity: The belief that some cosmic Jewish Zombie can make you live forever if you symbolically eat his flesh and telepathically tell him that you accept him as your master, so he can remove an evil force from your soul that is present in humanity because a rib-woman was convinced by a talking snake to eat from a magical tree. -- http://uncyclopedia.org/wiki/Christianity

On Mon, 2009-02-02 at 09:49 +1100, Erik de Castro Lopo wrote:
Hi all,
The following code creates a symbolic link in the current directory and then uses System.Posix.Files.getFileStatus to get the status of the link.
However, isDirectory returns True and isSymbolicLink returns False which is very different from what the stat() system call on a POSIX system would return. I consider this a bug.
No, it is the correct POSIX behaviour. You are thinking of lstat() which is what getSymbolicLinkStatus uses. The getFileStatus function calls stat(). The documentation makes this clear: http://www.haskell.org/ghc/docs/latest/html/libraries/unix/System-Posix-File... getFileStatus :: FilePath -> IO FileStatus getFileStatus path calls gets the FileStatus information (user ID, size, access times, etc.) for the file path. Note: calls stat. getSymbolicLinkStatus :: FilePath -> IO FileStatus Acts as getFileStatus except when the FilePath refers to a symbolic link. In that case the FileStatus information of the symbolic link itself is returned instead of that of the file it points to. Note: calls lstat. Duncan

Duncan Coutts wrote:
No, it is the correct POSIX behaviour. You are thinking of lstat() which is what getSymbolicLinkStatus uses. The getFileStatus function calls stat().
Maybe this is a naming issue. In C I think of "lstat" as "stat" but don't follow link. If getSymbolicLinkStatus was instead called getFileStatusNoFollowLink I think there would be less chance of confusion. Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "I once worked for a company where as part of the BS5750 "Quality" process I attended a meeting where I was informed that it was Company Policy not to use free software. When I asked him for his written authorisation for me to remove X Windows from our Sun workstations, he backtracked." -- Phil Hunt

On 2009 Feb 1, at 17:49, Erik de Castro Lopo wrote:
The following code creates a symbolic link in the current directory and then uses System.Posix.Files.getFileStatus to get the status of the link.
However, isDirectory returns True and isSymbolicLink returns False which is very different from what the stat() system call on a POSIX system would return. I consider this a bug.
Have you actually tried it? stat() on a symlink returns information about the target of the link; lstat() returns information about the link itself. These functions correspond to getFileStatus and getSymbolicLinkStatus respectively. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (3)
-
Brandon S. Allbery KF8NH
-
Duncan Coutts
-
Erik de Castro Lopo