diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 21:00:50 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 21:00:50 +0400 |
commit | 40f95ab06298d1f9d5e0b5d07ca14b9f81264692 (patch) | |
tree | ae1a9cb16cccd787a60129a88ef87c1d3a701dc2 /src/System/Torrent/Storage.hs | |
parent | 7f263c7569e907dc46d5583ae751a446950b5fdb (diff) |
Add basic tests for storage
Diffstat (limited to 'src/System/Torrent/Storage.hs')
-rw-r--r-- | src/System/Torrent/Storage.hs | 7 |
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 | ||
63 | instance Exception StorageFailure | 64 | instance Exception StorageFailure |
64 | 65 | ||
@@ -76,6 +77,10 @@ open mode s l = Storage mode s <$> mmapFiles mode l | |||
76 | close :: Storage -> IO () | 77 | close :: Storage -> IO () |
77 | close Storage {..} = unmapFiles fileMap | 78 | close Storage {..} = unmapFiles fileMap |
78 | 79 | ||
80 | withStorage :: Mode -> PieceSize -> FileLayout FileSize | ||
81 | -> (Storage -> IO ()) -> IO () | ||
82 | withStorage m s l = bracket (open m s l) close | ||
83 | |||
79 | isValidIx :: PieceIx -> Storage -> Bool | 84 | isValidIx :: PieceIx -> Storage -> Bool |
80 | isValidIx i s = 0 <= i && i < undefined s | 85 | isValidIx i s = 0 <= i && i < undefined s |
81 | 86 | ||