diff options
author | Sam T <sta.cs.vsu@gmail.com> | 2013-04-24 01:15:15 +0400 |
---|---|---|
committer | Sam T <sta.cs.vsu@gmail.com> | 2013-04-24 01:15:15 +0400 |
commit | d616ca9030d5420ff43e48c5b06738bec7230fc7 (patch) | |
tree | dc3a30e892ec66038046c9b3ea95ed1a4509a57b /src | |
parent | 0411025eb72ce0f5e5484b770d126779221b7c34 (diff) |
+ Add root path to contentLayout.
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Torrent.hs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index 226126f2..47a09cf5 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -17,6 +17,7 @@ module Data.Torrent | |||
17 | ) where | 17 | ) where |
18 | 18 | ||
19 | import Control.Applicative | 19 | import Control.Applicative |
20 | import Control.Arrow | ||
20 | import qualified Data.Map as M | 21 | import qualified Data.Map as M |
21 | import Data.ByteString (ByteString) | 22 | import Data.ByteString (ByteString) |
22 | import qualified Data.ByteString as B | 23 | import qualified Data.ByteString as B |
@@ -236,19 +237,19 @@ pieceCount ti = contentLength ti `sizeInBase` ciPieceLength ti | |||
236 | -- | 237 | -- |
237 | type Layout = [(FilePath, Int)] | 238 | type Layout = [(FilePath, Int)] |
238 | 239 | ||
239 | fileInfo :: ContentInfo -> [FileInfo] | 240 | contentLayout :: FilePath -> ContentInfo -> Layout |
240 | fileInfo (SingleFile { ciName = name, ciLength = len, ciMD5sum = md5 }) | 241 | contentLayout rootPath = filesLayout |
241 | = [FileInfo len md5 [name]] | 242 | where |
242 | fileInfo (MultiFile { ciFiles = fs }) = fs | 243 | filesLayout (SingleFile { ciName = name, ciLength = len }) |
244 | = [(rootPath </> BC.unpack name, fromIntegral len)] | ||
245 | filesLayout (MultiFile { ciFiles = fs, ciName = dir }) = | ||
246 | map (first mkPath . fl) fs | ||
247 | where -- TODO use utf8 encoding in name | ||
248 | mkPath = ((rootPath </> BC.unpack dir) </>) . joinPath . map BC.unpack | ||
243 | 249 | ||
244 | fileLayout :: FileInfo -> (FilePath, Int) | 250 | fl (FileInfo { fiPath = p, fiLength = len }) = (p, fromIntegral len) |
245 | fileLayout (FileInfo { fiLength = len, fiPath = name }) = (path, fromIntegral len) | ||
246 | where -- WARN use utf8 encoding in name | ||
247 | path = joinPath (map BC.unpack name) | ||
248 | 251 | ||
249 | 252 | ||
250 | contentLayout :: ContentInfo -> Layout | ||
251 | contentLayout = map fileLayout . fileInfo | ||
252 | 253 | ||
253 | 254 | ||
254 | -- | Read and decode a .torrent file. | 255 | -- | Read and decode a .torrent file. |