summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-14 21:53:19 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-14 21:53:19 +0400
commit01d48a9dc7d32869cff59369e6b4968473a49456 (patch)
tree0be810ab204bb9cc09abfc1b21b4393497fe8baa /src
parent39b3fd7d872153e1eafff38565b1df5d19adbe75 (diff)
Test InvalidIndex and InvalidSize exceptions
Diffstat (limited to 'src')
-rw-r--r--src/Data/Torrent/Layout.hs1
-rw-r--r--src/System/Torrent/Storage.hs6
2 files changed, 5 insertions, 2 deletions
diff --git a/src/Data/Torrent/Layout.hs b/src/Data/Torrent/Layout.hs
index 453c0d4f..a4b55b3d 100644
--- a/src/Data/Torrent/Layout.hs
+++ b/src/Data/Torrent/Layout.hs
@@ -56,6 +56,7 @@ module Data.Torrent.Layout
56 , fileOffset 56 , fileOffset
57 57
58 -- * Internal 58 -- * Internal
59 , sizeInBase
59 , getLayoutInfo 60 , getLayoutInfo
60 , putLayoutInfo 61 , putLayoutInfo
61 ) where 62 ) where
diff --git a/src/System/Torrent/Storage.hs b/src/System/Torrent/Storage.hs
index bf44d7bf..8ad4d3e5 100644
--- a/src/System/Torrent/Storage.hs
+++ b/src/System/Torrent/Storage.hs
@@ -45,7 +45,7 @@ import Data.Typeable
45import Data.Torrent.Bitfield 45import Data.Torrent.Bitfield
46import Data.Torrent.Layout 46import Data.Torrent.Layout
47import Data.Torrent.Piece 47import Data.Torrent.Piece
48import System.Torrent.FileMap 48import System.Torrent.FileMap as FM
49 49
50 50
51data StorageFailure 51data StorageFailure
@@ -82,7 +82,9 @@ withStorage :: Mode -> PieceSize -> FileLayout FileSize
82withStorage m s l = bracket (open m s l) close 82withStorage m s l = bracket (open m s l) close
83 83
84isValidIx :: PieceIx -> Storage -> Bool 84isValidIx :: PieceIx -> Storage -> Bool
85isValidIx i s = 0 <= i && i < undefined s 85isValidIx i Storage {..} = 0 <= i && i < pcount
86 where
87 pcount = FM.size fileMap `sizeInBase` pieceLen
86 88
87writePiece :: Piece BL.ByteString -> Storage -> IO () 89writePiece :: Piece BL.ByteString -> Storage -> IO ()
88writePiece p @ Piece {..} s @ Storage {..} 90writePiece p @ Piece {..} s @ Storage {..}