From: Ramakrishnan Muthukrishnan Date: Sat, 25 Jun 2016 04:51:22 +0000 (+0530) Subject: more hlint fixes X-Git-Url: https://git.rkrishnan.org/vdrive/nxhtml.html?a=commitdiff_plain;h=08f3238a8162039a1b77f4fb8825a56a34203c02;p=functorrent.git more hlint fixes --- diff --git a/src/FuncTorrent/FileSystem.hs b/src/FuncTorrent/FileSystem.hs index 5568b77..7c95c1e 100644 --- a/src/FuncTorrent/FileSystem.hs +++ b/src/FuncTorrent/FileSystem.hs @@ -86,7 +86,7 @@ run' pieceMap c handle = do VerifyPiece n var -> do isHashValid <- verifyPiece n putMVar var isHashValid - GetStats var -> do + GetStats var -> putMVar var stats readPiece n len' = do let offset = pieceNumToOffset pieceMap n diff --git a/src/FuncTorrent/Network.hs b/src/FuncTorrent/Network.hs index ca4b6d9..99243f6 100644 --- a/src/FuncTorrent/Network.hs +++ b/src/FuncTorrent/Network.hs @@ -40,6 +40,6 @@ sendGetRequest :: String -> [(String, ByteString)] -> IO ByteString sendGetRequest url args = simpleHTTP (defaultGETRequest_ url') >>= getResponseBody where url' = case parseURI url'' of Just x -> x - _ -> error $ "Bad tracker URL: " ++ (show url'') + _ -> error $ "Bad tracker URL: " ++ show url'' qstr = mkParams args url'' = unpack $ concat [pack url, "?", qstr] diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs index 63aaa5a..c833c06 100644 --- a/src/FuncTorrent/Peer.hs +++ b/src/FuncTorrent/Peer.hs @@ -166,7 +166,7 @@ msgLoop pieceStatus msgchannel = do NotInterestedMsg -> do modify (\st' -> st' {heInterested = False}) msgLoop pieceStatus msgchannel - CancelMsg _ _ _ -> -- check if valid index, begin, length + CancelMsg {} -> -- check if valid index, begin, length msgLoop pieceStatus msgchannel PortMsg _ -> msgLoop pieceStatus msgchannel @@ -175,7 +175,7 @@ msgLoop pieceStatus msgchannel = do let pieceStatus' = updatePieceAvailability pieceStatus p [idx] msgLoop pieceStatus' msgchannel _ -> do - liftIO $ putStrLn $ ".. not doing anything with the msg" + liftIO $ putStrLn ".. not doing anything with the msg" msgLoop pieceStatus msgchannel -- No need to handle PieceMsg and RequestMsg here. diff --git a/src/FuncTorrent/PeerMsgs.hs b/src/FuncTorrent/PeerMsgs.hs index ff3b435..f597ed8 100644 --- a/src/FuncTorrent/PeerMsgs.hs +++ b/src/FuncTorrent/PeerMsgs.hs @@ -86,9 +86,7 @@ instance Binary PeerMsg where bfListLen = length bfList RequestMsg i o l -> do putWord32be 13 putWord8 6 - putWord32be (fromIntegral i) - putWord32be (fromIntegral o) - putWord32be (fromIntegral l) + putIndexOffsetLength i o l PieceMsg i o b -> do putWord32be $ fromIntegral (9 + blocklen) putWord8 7 putWord32be (fromIntegral i) @@ -98,12 +96,15 @@ instance Binary PeerMsg where blocklen = length blockList CancelMsg i o l -> do putWord32be 13 putWord8 8 - putWord32be (fromIntegral i) - putWord32be (fromIntegral o) - putWord32be (fromIntegral l) + putIndexOffsetLength i o l PortMsg p -> do putWord32be 3 putWord8 9 putWord16be (fromIntegral p) + where putIndexOffsetLength i o l = do + putWord32be (fromIntegral i) + putWord32be (fromIntegral o) + putWord32be (fromIntegral l) + get = do l <- getWord32be msgid <- getWord8 @@ -112,15 +113,15 @@ instance Binary PeerMsg where 1 -> return UnChokeMsg 2 -> return InterestedMsg 3 -> return NotInterestedMsg - 4 -> liftM (HaveMsg . fromIntegral) getWord32be - 5 -> liftM (BitFieldMsg . pack) (replicateM (fromIntegral l - 1) getWord8) + 4 -> fmap (HaveMsg . fromIntegral) getWord32be + 5 -> fmap (BitFieldMsg . pack) (replicateM (fromIntegral l - 1) getWord8) 6 -> liftA3 RequestMsg getInteger getInteger getInteger where getInteger = fromIntegral <$> getWord32be 7 -> liftA3 PieceMsg getInteger getInteger (pack <$> replicateM (fromIntegral l - 9) getWord8) where getInteger = fromIntegral <$> getWord32be 8 -> liftA3 CancelMsg getInteger getInteger getInteger where getInteger = fromIntegral <$> getWord32be - 9 -> liftM (PortMsg . fromIntegral) getWord16be + 9 -> fmap (PortMsg . fromIntegral) getWord16be _ -> error ("unknown message ID: " ++ show msgid) getMsg :: Handle -> IO PeerMsg diff --git a/src/FuncTorrent/Utils.hs b/src/FuncTorrent/Utils.hs index be4e15b..30fd160 100644 --- a/src/FuncTorrent/Utils.hs +++ b/src/FuncTorrent/Utils.hs @@ -60,7 +60,7 @@ createDummyFile :: FilePath -> Int -> IO (Either IOException ()) createDummyFile path size = do dfe <- doesFileExist path if not dfe - then do + then try $ writeFile path (BC.replicate size '\0') else return $ Right ()