summaryrefslogtreecommitdiff
path: root/data/make-reference-files.hs
diff options
context:
space:
mode:
authorNikolay Yakimov <root@livid.pp.ru>2015-03-18 22:33:16 +0300
committerJohn MacFarlane <jgm@berkeley.edu>2015-03-28 10:36:53 -0700
commitd744b83b61bc635419339b73b687b9280ee757fc (patch)
treeef1def7314f5ce87e4a11a18aaf2172a254935e6 /data/make-reference-files.hs
parent1710c4bd8bc66dcd755029dc8ed05a9eb35d71f6 (diff)
Create reference files from unpacked archives with helper program
Diffstat (limited to 'data/make-reference-files.hs')
-rw-r--r--data/make-reference-files.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/data/make-reference-files.hs b/data/make-reference-files.hs
new file mode 100644
index 000000000..2e64dc51f
--- /dev/null
+++ b/data/make-reference-files.hs
@@ -0,0 +1,26 @@
+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)
+
+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)