2015-03-18 20:33:16 +01:00
|
|
|
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)
|
2015-05-28 18:59:08 +02:00
|
|
|
import System.FilePath
|
2015-03-18 20:33:16 +01:00
|
|
|
|
|
|
|
mkzip :: String -> IO ()
|
|
|
|
mkzip fmt = do
|
2015-05-28 18:59:08 +02:00
|
|
|
let dir = "data" </> fmt
|
|
|
|
output = "data" </> "reference" <.> fmt
|
2015-03-18 20:33:16 +01:00
|
|
|
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)
|