pandoc/data/make-reference-files.hs
John MacFarlane 3a9d5d878c make-reference-files: use proper path separators for Windows.
Fixes a bug with reference.docx and reference.odt in Windows
builds.
2015-05-28 09:59:08 -07:00

27 lines
815 B
Haskell

import System.Environment
import System.Directory
import Codec.Archive.Zip
import qualified Data.ByteString.Lazy as BS
import qualified Control.Exception as E
import System.IO.Error (isDoesNotExistError)
import System.FilePath
mkzip :: String -> IO ()
mkzip fmt = do
let dir = "data" </> fmt
output = "data" </> "reference" <.> fmt
cd <- getCurrentDirectory
setCurrentDirectory dir
archive <- addFilesToArchive [OptRecursive] emptyArchive ["."]
setCurrentDirectory cd
removeIfExists output
BS.writeFile output $ fromArchive archive
removeIfExists :: FilePath -> IO ()
removeIfExists fileName = removeFile fileName `E.catch` handleExists
where handleExists e
| isDoesNotExistError e = return ()
| otherwise = E.throwIO e
main :: IO ()
main = getArgs >>= mkzip . (!!0)