summaryrefslogtreecommitdiff
path: root/src/System
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-14 21:00:50 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-14 21:00:50 +0400
commit40f95ab06298d1f9d5e0b5d07ca14b9f81264692 (patch)
treeae1a9cb16cccd787a60129a88ef87c1d3a701dc2 /src/System
parent7f263c7569e907dc46d5583ae751a446950b5fdb (diff)
Add basic tests for storage
Diffstat (limited to 'src/System')
-rw-r--r--src/System/Torrent/Storage.hs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/System/Torrent/Storage.hs b/src/System/Torrent/Storage.hs
index 71e0616b..bf44d7bf 100644
--- a/src/System/Torrent/Storage.hs
+++ b/src/System/Torrent/Storage.hs
@@ -25,6 +25,7 @@ module System.Torrent.Storage
25 , def 25 , def
26 , open 26 , open
27 , close 27 , close
28 , withStorage
28 29
29 -- * Query 30 -- * Query
30 , genPieceInfo 31 , genPieceInfo
@@ -58,7 +59,7 @@ data StorageFailure
58 -- | Piece size do not match with one passed to the 'open' 59 -- | Piece size do not match with one passed to the 'open'
59 -- function. 60 -- function.
60 | InvalidSize PieceSize 61 | InvalidSize PieceSize
61 deriving (Show, Typeable) 62 deriving (Show, Eq, Typeable)
62 63
63instance Exception StorageFailure 64instance Exception StorageFailure
64 65
@@ -76,6 +77,10 @@ open mode s l = Storage mode s <$> mmapFiles mode l
76close :: Storage -> IO () 77close :: Storage -> IO ()
77close Storage {..} = unmapFiles fileMap 78close Storage {..} = unmapFiles fileMap
78 79
80withStorage :: Mode -> PieceSize -> FileLayout FileSize
81 -> (Storage -> IO ()) -> IO ()
82withStorage m s l = bracket (open m s l) close
83
79isValidIx :: PieceIx -> Storage -> Bool 84isValidIx :: PieceIx -> Storage -> Bool
80isValidIx i s = 0 <= i && i < undefined s 85isValidIx i s = 0 <= i && i < undefined s
81 86