-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
removeFile did not remove file or throw errors. #12
Comments
I wonder if this is related to #4 |
I tried the test program and I don't believe the problem is related to directory. The temporary file appears to have been created asynchronously, long after |
Why would the file be created asynchronously? Anyway, I can't reproduce the issue on Fedora 21 (and same ghc/directory versions as OP's) with main = curl "http://google.com" Nothing >>= (print :: Either CurlCode String -> IO ()) |
I don't know. Something odd about the curl library. Perhaps Polling the existence of the file at 1 sec intervals:
Here's the code I used: import Control.Concurrent
import Control.Monad
import Network.Curl
import System.Posix.Temp
import System.Directory
import System.IO
import System.FilePath
import Control.Exception
type PostField = (String, String)
withTemp :: String -> (FilePath -> IO a) -> IO a
withTemp prefix f = do
tmp <- getTemporaryDirectory
(fp, h) <- mkstemp $ tmp </> prefix
hClose h
finally (f fp) $ do
putStr ("withTemp: does " ++ fp ++ " exist? ")
print =<< doesFileExist fp
threadDelay 1000000
removeFile fp
putStrLn ("withTemp: file " ++ fp ++ " has been removed")
curl :: URLString -> Maybe [PostField] -> IO (FilePath, Either CurlCode String)
curl url values = do
let mPf = fmap (map (\(k, v) -> k ++ "=" ++ v)) values
(tmp, (cc, ty)) <- withTemp "Cookie" $ \tmp -> fmap (\x -> (tmp, x)) $ withCurlDo $
let curlOpts_ = [ CurlHttpAuth [HttpAuthAny]
, CurlUserPwd ":"
, CurlCookieFile tmp
, CurlCookieJar tmp
, CurlFollowLocation True
, CurlUnrestrictedAuth True ]
curlOpts = case mPf of
Nothing -> curlOpts_
Just pf -> (CurlPostFields pf) : curlOpts_
in curlGetString_ url curlOpts
return $ (,) tmp $ if cc == CurlOK
then Right ty
else Left cc
main :: IO ()
main = do
(path, result) <- curl "http://google.com" Nothing
putStr ("main: does " ++ path ++ " exist? ")
print =<< doesFileExist path
threadDelay 1000000
putStr "main: curl returned (truncated):\n "
print (take 80 `fmap` result)
putStr " "
print (length `fmap` result) -- must force result to NF completely!
forever $ do
putStr ("main: does " ++ path ++ " exist? ")
print =<< doesFileExist path
threadDelay 1000000 Marking as invalid since the problem is not due to directory. |
Seeing as how this is a "can't fix, won't fix", is there a compelling reason to keep it open? |
I left it open to see if anyone else has any comments. |
@Rufflewind thanks for the test case, but again, I can't reproduce it. On my system, it never gets to True for the second time. |
@feuerbach I'm using a slightly different version of GHC (7.8.4) but I doubt that's the source of the problem. Mind if I ask what version of libcurl and curl you use? I use curl-1.3.8 and libcurl-7.40.0. Edit: apparently the version number on libcurl.so is wrong. |
curl 1.3.8.1, libcurl 7.37.0 |
Hrm, I'm not sure what the problem is. I built and linked against curl-7.37.0 and the test case still works for me. Furthermore, curl-1.3.8.1 looks virtually identical to curl-1.3.8 modulo some documentation changes and a version bump. |
Bug fixes for normalise haskell#12
In the following code, in
withTemp
function, afterremoveFile fp
, the temp file was still there. I tried to usetry
to catchIOException
that may throw byremoveFile
. I just gotRight ()
.It is Ubuntu Trusty, ghc 7.8.3, directory 1.2.1.0.
The text was updated successfully, but these errors were encountered: