isSymbolicLink or stat function returns wrong result
zoranbosnjak opened this issue · comments
isSymbolicLink
or stat
function does not work as expected. It returns False
on actual symlink. However, isNotSymbolicLink
function works as expected. Tested with turtle-1.5.16
, using nix-shell
on ubuntu-16.04
. This is a simple test program:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (FilePath)
import Turtle
-- | Create a file and a symlink, check symlink.
main :: IO ()
main = do
let filename = "test.txt"
linkname = "linkToFile"
writeTextFile filename "some text"
symlink filename linkname
isSymbolicLink <$> stat linkname >>= print -- Problem, expected True, got False.
isNotSymbolicLink linkname >>= print -- OK, got False as expected.
@zoranbosnjak: It's because stat
follows symbolic links, whereas lstat
does not follow symbolic links. See their respective documentation here:
- https://hackage.haskell.org/package/turtle-1.5.16/docs/Turtle-Prelude.html#v:stat
- https://hackage.haskell.org/package/turtle-1.5.16/docs/Turtle-Prelude.html#v:lstat
So the reason the first version returns False
is because it's actually getting the FileStatus
for the file that the symbolic link is pointing to and not the link itself.
@Gabriel439: Thank you, I was not aware of lstat
.
@zoranbosnjak: You're welcome! 🙂