@@ -51,7 +51,7 @@ import System.IO (stderr)
51-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
51-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
52-- can be used for an empty 'MediaBag', and '<>' can be used to append
52-- can be used for an empty 'MediaBag', and '<>' can be used to append
53-- two 'MediaBag's.
53-- two 'MediaBag's.
54−newtype MediaBag = MediaBag (M.Map String (MimeType, BL.ByteString))
54+newtype MediaBag = MediaBag (M.Map [String] (MimeType, BL.ByteString))
55 deriving (Monoid)
55 deriving (Monoid)
57instance Show MediaBag where
57instance Show MediaBag where
@@ -65,7 +65,7 @@ insertMedia :: FilePath -- ^ relative path and canonical name of resource
65 -> MediaBag
65 -> MediaBag
66 -> MediaBag
66 -> MediaBag
67insertMedia fp mbMime contents (MediaBag mediamap) =
67insertMedia fp mbMime contents (MediaBag mediamap) =
68− MediaBag (M.insert fp (mime, contents) mediamap)
68+ MediaBag (M.insert (splitPath fp) (mime, contents) mediamap)
69 where mime = fromMaybe fallback mbMime
69 where mime = fromMaybe fallback mbMime
70 fallback = case takeExtension fp of
70 fallback = case takeExtension fp of
71 ".gz" -> getMimeTypeDef $ dropExtension fp
71 ".gz" -> getMimeTypeDef $ dropExtension fp
@@ -75,14 +75,14 @@ insertMedia fp mbMime contents (MediaBag mediamap) =
75lookupMedia :: FilePath
75lookupMedia :: FilePath
76 -> MediaBag
76 -> MediaBag
77 -> Maybe (MimeType, BL.ByteString)
77 -> Maybe (MimeType, BL.ByteString)
78−lookupMedia fp (MediaBag mediamap) = M.lookup fp mediamap
78+lookupMedia fp (MediaBag mediamap) = M.lookup (splitPath fp) mediamap
80-- | Get a list of the file paths stored in a 'MediaBag', with
80-- | Get a list of the file paths stored in a 'MediaBag', with
81-- their corresponding mime types and the lengths in bytes of the contents.
81-- their corresponding mime types and the lengths in bytes of the contents.
82mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
82mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
83mediaDirectory (MediaBag mediamap) =
83mediaDirectory (MediaBag mediamap) =
84 M.foldWithKey (\fp (mime,contents) ->
84 M.foldWithKey (\fp (mime,contents) ->
85− ((fp, mime, fromIntegral $ BL.length contents):)) [] mediamap
85+ (((joinPath fp), mime, fromIntegral $ BL.length contents):)) [] mediamap
87-- | Extract contents of MediaBag to a given directory. Print informational
87-- | Extract contents of MediaBag to a given directory. Print informational
88-- messages if 'verbose' is true.
88-- messages if 'verbose' is true.
@@ -93,7 +93,7 @@ extractMediaBag :: Bool
93extractMediaBag verbose dir (MediaBag mediamap) = do
93extractMediaBag verbose dir (MediaBag mediamap) = do
94 sequence_ $ M.foldWithKey
94 sequence_ $ M.foldWithKey
95 (\fp (_ ,contents) ->
95 (\fp (_ ,contents) ->
96− ((writeMedia verbose dir (fp, contents)):)) [] mediamap
96+ ((writeMedia verbose dir (joinPath fp, contents)):)) [] mediamap
98writeMedia :: Bool -> FilePath -> (FilePath, BL.ByteString) -> IO ()
98writeMedia :: Bool -> FilePath -> (FilePath, BL.ByteString) -> IO ()
99writeMedia verbose dir (subpath, bs) = do
99writeMedia verbose dir (subpath, bs) = do