From 40f95ab06298d1f9d5e0b5d07ca14b9f81264692 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sat, 14 Dec 2013 21:00:50 +0400 Subject: Add basic tests for storage --- src/System/Torrent/Storage.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/System') 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 , def , open , close + , withStorage -- * Query , genPieceInfo @@ -58,7 +59,7 @@ data StorageFailure -- | Piece size do not match with one passed to the 'open' -- function. | InvalidSize PieceSize - deriving (Show, Typeable) + deriving (Show, Eq, Typeable) instance Exception StorageFailure @@ -76,6 +77,10 @@ open mode s l = Storage mode s <$> mmapFiles mode l close :: Storage -> IO () close Storage {..} = unmapFiles fileMap +withStorage :: Mode -> PieceSize -> FileLayout FileSize + -> (Storage -> IO ()) -> IO () +withStorage m s l = bracket (open m s l) close + isValidIx :: PieceIx -> Storage -> Bool isValidIx i s = 0 <= i && i < undefined s -- cgit v1.2.3