It's not a file permission problem because it works great when the file exists. But, when the file doesn't exist, it still tries to read the file. It acts like the file is there when it isn't. In ghci, it returns the true boolean when the file is there and a false when it isn't. But, in the program, it is always executing the readFile.

Kim-Ee Yeoh wrote:


On Wed, Mar 4, 2015 at 12:38 PM, Richard Guay <raguay@customct.com
<mailto:raguay@customct.com>> wrote:

        fExist <- doesFileExist $ h ++ cacheDirBasic ++ getBundleID ++
    "/" ++ fileName
        if fExist
        then do
            contents <- readFile $ h ++ cacheDirBasic ++ getBundleID
    ++ "/" ++ fileName


First of all, let's refactor that into a let binding, e.g.

    let pathName = h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName
    fExist <- doesFileExist pathName
    if fExist then readFile pathName else return ""

The advantage of keeping DRY here should be obvious. Defining the same
thing in 2 places can lead to both getting out of lockstep.

Now as for debugging the actual problem, have you tried the REPL? That
is, launch ghci, load the appropriate libraries, and see what happens
when you enter

doesFileExist "/home/me/myfile"

and similarly for readFile. That way you'd rule things out like a file
permissions problem, etc.


-- Kim-Ee
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners