]> git.rkrishnan.org Git - functorrent.git/commitdiff
functorrent.cabal: avoid double compilation, one for lib, another for exe
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 11 Sep 2015 08:03:11 +0000 (13:33 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 11 Sep 2015 08:04:58 +0000 (13:34 +0530)
functorrent.cabal
src/FuncTorrent.hs [deleted file]
src/Main.hs [deleted file]
src/main/Main.hs [new file with mode: 0644]

index 2ec81bb1dfa020d9f04fe30acc52b0b2d4d4d233..b663ef9e7ea75f1fb31738ffe17a1f5ff515a2ae 100644 (file)
@@ -16,15 +16,16 @@ extra-source-files:  README.md
 cabal-version:       >=1.18
 
 library
-  exposed-modules:     FuncTorrent
-                       FuncTorrent.Bencode,
+  exposed-modules:     FuncTorrent.Bencode,
+                       FuncTorrent.Fileops,
                        FuncTorrent.Logger,
                        FuncTorrent.Metainfo,
                        FuncTorrent.Network
                        FuncTorrent.Peer,
-                       FuncTorrent.Tracker
+                       FuncTorrent.PeerMsgs,
+                       FuncTorrent.Tracker,
+                       FuncTorrent.Utils
 
-  other-modules:       FuncTorrent.Utils
   other-extensions:    OverloadedStrings
   hs-source-dirs:      src
   ghc-options:         -Wall -fwarn-incomplete-patterns -fno-warn-orphans
@@ -49,7 +50,7 @@ library
 executable functorrent
   main-is:             Main.hs
   other-extensions:    OverloadedStrings
-  hs-source-dirs:      src
+  hs-source-dirs:      src/main
   ghc-options:         -Wall -fwarn-incomplete-patterns -optc-Os -fno-warn-orphans
   default-language:    Haskell2010
   build-depends:       base,
@@ -59,6 +60,7 @@ executable functorrent
                        containers,
                        cryptohash,
                        directory,
+                       functorrent,
                        HTTP,
                        mtl,
                        network,
diff --git a/src/FuncTorrent.hs b/src/FuncTorrent.hs
deleted file mode 100644 (file)
index 2cded5b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-module FuncTorrent
-    (BVal(..),
-     Info(..),
-     Metainfo(..),
-     Peer,
-     TrackerResponse(..),
-     getTrackerResponse,
-     decode,
-     encode,
-     handlePeerMsgs,
-     initLogger,
-     logMessage,
-     logStop,
-     mkInfo,
-     torrentToMetainfo
-    ) where
-
-import FuncTorrent.Bencode
-import FuncTorrent.Logger
-import FuncTorrent.Metainfo
-import FuncTorrent.Peer
-import FuncTorrent.Tracker
diff --git a/src/Main.hs b/src/Main.hs
deleted file mode 100644 (file)
index 3aa6587..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-module Main where
-
-import Prelude hiding (log, length, readFile, getContents)
-import Data.ByteString.Char8 (ByteString, getContents, readFile, unpack)
-import System.Environment (getArgs)
-import System.Exit (exitSuccess)
-import System.Directory (doesFileExist)
-
-import FuncTorrent.Logger (initLogger, logMessage, logStop)
-import FuncTorrent.Metainfo (Info(..), Metainfo(..), torrentToMetainfo)
-import FuncTorrent.Peer (handlePeerMsgs)
-import FuncTorrent.Tracker (peers, getTrackerResponse)
-
-logError :: String -> (String -> IO ()) -> IO ()
-logError e logMsg = logMsg $ "parse error: \n" ++ e
-
-peerId :: String
-peerId = "-HS0001-*-*-20150215"
-
-exit :: IO ByteString
-exit = exitSuccess
-
-usage :: IO ()
-usage = putStrLn "usage: functorrent torrent-file"
-
-parse :: [String] -> IO ByteString
-parse [] = getContents
-parse [a] = do
-  fileExist <- doesFileExist a
-  if fileExist
-    then readFile a
-    else error "file does not exist"
-parse _ = exit
-
-main :: IO ()
-main = do
-    args <- getArgs
-    logR <- initLogger
-    let log = logMessage logR
-    log "Starting up functorrent"
-    log $ "Parsing arguments " ++ concat args
-    torrentStr <- parse args
-    case torrentToMetainfo torrentStr of
-     Left e -> logError e log
-     Right m -> do
-       log "Input File OK"
-       log $ "Downloading file : " ++ name (info m)
-       log "Trying to fetch peers"
-
-       log $ "Trackers: " ++ head (announceList m)
-       trackerResp <- getTrackerResponse m peerId
-       case  trackerResp of
-        Left e -> log $ "Error" ++ unpack e
-        Right peerList -> do
-          log $ "Peers List : " ++ (show . peers $ peerList)
-          let p1 = head (peers peerList)
-          handlePeerMsgs p1 m peerId
-    logStop logR
diff --git a/src/main/Main.hs b/src/main/Main.hs
new file mode 100644 (file)
index 0000000..3aa6587
--- /dev/null
@@ -0,0 +1,59 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Main where
+
+import Prelude hiding (log, length, readFile, getContents)
+import Data.ByteString.Char8 (ByteString, getContents, readFile, unpack)
+import System.Environment (getArgs)
+import System.Exit (exitSuccess)
+import System.Directory (doesFileExist)
+
+import FuncTorrent.Logger (initLogger, logMessage, logStop)
+import FuncTorrent.Metainfo (Info(..), Metainfo(..), torrentToMetainfo)
+import FuncTorrent.Peer (handlePeerMsgs)
+import FuncTorrent.Tracker (peers, getTrackerResponse)
+
+logError :: String -> (String -> IO ()) -> IO ()
+logError e logMsg = logMsg $ "parse error: \n" ++ e
+
+peerId :: String
+peerId = "-HS0001-*-*-20150215"
+
+exit :: IO ByteString
+exit = exitSuccess
+
+usage :: IO ()
+usage = putStrLn "usage: functorrent torrent-file"
+
+parse :: [String] -> IO ByteString
+parse [] = getContents
+parse [a] = do
+  fileExist <- doesFileExist a
+  if fileExist
+    then readFile a
+    else error "file does not exist"
+parse _ = exit
+
+main :: IO ()
+main = do
+    args <- getArgs
+    logR <- initLogger
+    let log = logMessage logR
+    log "Starting up functorrent"
+    log $ "Parsing arguments " ++ concat args
+    torrentStr <- parse args
+    case torrentToMetainfo torrentStr of
+     Left e -> logError e log
+     Right m -> do
+       log "Input File OK"
+       log $ "Downloading file : " ++ name (info m)
+       log "Trying to fetch peers"
+
+       log $ "Trackers: " ++ head (announceList m)
+       trackerResp <- getTrackerResponse m peerId
+       case  trackerResp of
+        Left e -> log $ "Error" ++ unpack e
+        Right peerList -> do
+          log $ "Peers List : " ++ (show . peers $ peerList)
+          let p1 = head (peers peerList)
+          handlePeerMsgs p1 m peerId
+    logStop logR