[Haskell-cafe] System.Posix.Files.isDirectory and System.Posix.Files.isSymbolicLink

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sun Feb 1 19:05:08 EST 2009


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-Files.html#5

        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



More information about the Haskell-Cafe mailing list