File: make-reference-files.hs

package info (click to toggle)
pandoc 2.9.2.1-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 23,412 kB
  • sloc: haskell: 63,627; xml: 3,294; makefile: 325; sh: 137; perl: 51; lisp: 32
file content (27 lines) | stat: -rw-r--r-- 815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)