- let fn = filename url
- case fn of
- Nothing -> return Nothing
- Just file -> do
- temp_dir <- getTemporaryDirectory
- (out_path, out_handle) <- openBinaryTempFile temp_dir file
- result <- openURI url
- case result of
- Left err -> do
- hPutStrLn stderr ("HTTP Error: " ++ err)
- return Nothing
- Right bs -> do
- B.hPut out_handle bs
- return $ Just out_path
+ it_exists <- doesFileExist url
+ if it_exists then do
+ -- It's local, just use it.
+ return $ Just url
+ else do
+ let fn = filename url
+ case fn of
+ Nothing -> return Nothing
+ Just file -> do
+ temp_dir <- getTemporaryDirectory
+ (out_path, out_handle) <- openBinaryTempFile temp_dir file
+ result <- openURI url
+ case result of
+ Left err -> do
+ hPutStrLn stderr ("HTTP Error: " ++ err)
+ return Nothing
+ Right bs -> do
+ B.hPut out_handle bs
+ return $ Just out_path