]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/Main.hs
error out if the input string is not a valid filepath
[functorrent.git] / src / Main.hs
index 17bd05355c8032608409f1b8a26026a8062e17d1..d0812656c5498d30166c6b762c8ba6038a15f77c 100644 (file)
@@ -5,6 +5,7 @@ import Prelude hiding (length, readFile, writeFile)
 import Data.ByteString.Char8 (ByteString, readFile, writeFile, length)
 import System.Environment (getArgs)
 import System.Exit (exitSuccess)
+import System.Directory (doesFileExist)
 import Text.ParserCombinators.Parsec (ParseError)
 
 import FuncTorrent.Bencode (decode, BVal(..))
@@ -27,7 +28,11 @@ usage = putStrLn "usage: functorrent torrent-file"
 
 parse :: [String] -> IO ByteString
 parse [] = usage >> exit
-parse [a] = readFile a
+parse [a] = do
+  fileExist <- doesFileExist a
+  if fileExist
+    then readFile a
+    else error "file does not exist"
 parse _ = exit
 
 main :: IO ()