MediaBag: Fixes Windows specific path problems
Changes the internal representation to fix the problem. I haven't tested this on windows. Closes #1597
This commit is contained in:
parent
0fbe7df818
commit
56e4ecab20
1 changed files with 5 additions and 5 deletions
|
@ -51,7 +51,7 @@ import System.IO (stderr)
|
||||||
-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
|
-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
|
||||||
-- can be used for an empty 'MediaBag', and '<>' can be used to append
|
-- can be used for an empty 'MediaBag', and '<>' can be used to append
|
||||||
-- two 'MediaBag's.
|
-- two 'MediaBag's.
|
||||||
newtype MediaBag = MediaBag (M.Map String (MimeType, BL.ByteString))
|
newtype MediaBag = MediaBag (M.Map [String] (MimeType, BL.ByteString))
|
||||||
deriving (Monoid)
|
deriving (Monoid)
|
||||||
|
|
||||||
instance Show MediaBag where
|
instance Show MediaBag where
|
||||||
|
@ -65,7 +65,7 @@ insertMedia :: FilePath -- ^ relative path and canonical name of resource
|
||||||
-> MediaBag
|
-> MediaBag
|
||||||
-> MediaBag
|
-> MediaBag
|
||||||
insertMedia fp mbMime contents (MediaBag mediamap) =
|
insertMedia fp mbMime contents (MediaBag mediamap) =
|
||||||
MediaBag (M.insert fp (mime, contents) mediamap)
|
MediaBag (M.insert (splitPath fp) (mime, contents) mediamap)
|
||||||
where mime = fromMaybe fallback mbMime
|
where mime = fromMaybe fallback mbMime
|
||||||
fallback = case takeExtension fp of
|
fallback = case takeExtension fp of
|
||||||
".gz" -> getMimeTypeDef $ dropExtension fp
|
".gz" -> getMimeTypeDef $ dropExtension fp
|
||||||
|
@ -75,14 +75,14 @@ insertMedia fp mbMime contents (MediaBag mediamap) =
|
||||||
lookupMedia :: FilePath
|
lookupMedia :: FilePath
|
||||||
-> MediaBag
|
-> MediaBag
|
||||||
-> Maybe (MimeType, BL.ByteString)
|
-> Maybe (MimeType, BL.ByteString)
|
||||||
lookupMedia fp (MediaBag mediamap) = M.lookup fp mediamap
|
lookupMedia fp (MediaBag mediamap) = M.lookup (splitPath fp) mediamap
|
||||||
|
|
||||||
-- | Get a list of the file paths stored in a 'MediaBag', with
|
-- | Get a list of the file paths stored in a 'MediaBag', with
|
||||||
-- their corresponding mime types and the lengths in bytes of the contents.
|
-- their corresponding mime types and the lengths in bytes of the contents.
|
||||||
mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
|
mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
|
||||||
mediaDirectory (MediaBag mediamap) =
|
mediaDirectory (MediaBag mediamap) =
|
||||||
M.foldWithKey (\fp (mime,contents) ->
|
M.foldWithKey (\fp (mime,contents) ->
|
||||||
((fp, mime, fromIntegral $ BL.length contents):)) [] mediamap
|
(((joinPath fp), mime, fromIntegral $ BL.length contents):)) [] mediamap
|
||||||
|
|
||||||
-- | Extract contents of MediaBag to a given directory. Print informational
|
-- | Extract contents of MediaBag to a given directory. Print informational
|
||||||
-- messages if 'verbose' is true.
|
-- messages if 'verbose' is true.
|
||||||
|
@ -93,7 +93,7 @@ extractMediaBag :: Bool
|
||||||
extractMediaBag verbose dir (MediaBag mediamap) = do
|
extractMediaBag verbose dir (MediaBag mediamap) = do
|
||||||
sequence_ $ M.foldWithKey
|
sequence_ $ M.foldWithKey
|
||||||
(\fp (_ ,contents) ->
|
(\fp (_ ,contents) ->
|
||||||
((writeMedia verbose dir (fp, contents)):)) [] mediamap
|
((writeMedia verbose dir (joinPath fp, contents)):)) [] mediamap
|
||||||
|
|
||||||
writeMedia :: Bool -> FilePath -> (FilePath, BL.ByteString) -> IO ()
|
writeMedia :: Bool -> FilePath -> (FilePath, BL.ByteString) -> IO ()
|
||||||
writeMedia verbose dir (subpath, bs) = do
|
writeMedia verbose dir (subpath, bs) = do
|
||||||
|
|
Loading…
Add table
Reference in a new issue