GenIndex.hs 1.06 KB
Newer Older
Ben Gamari's avatar
Ben Gamari committed
1 2 3 4 5 6 7 8 9 10 11
import Data.List
import Data.Maybe
import System.Environment

import System.Directory
import System.FilePath
import Hakyll
import Types

collectFiles :: FilePath -> IO [DownloadFile]
collectFiles root = do
Ben Gamari's avatar
Ben Gamari committed
12
    getRecursiveContents (return . isHidden) root >>= fmap catMaybes . mapM toDownloadFile
Ben Gamari's avatar
Ben Gamari committed
13
  where
Ben Gamari's avatar
Ben Gamari committed
14
    isHidden path = "." `isPrefixOf` takeFileName path
Ben Gamari's avatar
Ben Gamari committed
15 16 17 18 19
    isTarball name = ".tar.gz"  `isSuffixOf` name
                  || ".tar.bz2" `isSuffixOf` name
                  || ".tar.xz"  `isSuffixOf` name
    toDownloadFile path
      | isTarball path = do
Ben Gamari's avatar
Ben Gamari committed
20
        let sigPath = path <.> "sig"
Ben Gamari's avatar
Ben Gamari committed
21

Ben Gamari's avatar
Ben Gamari committed
22
        sig <- doesFileExist (root </> sigPath)
Ben Gamari's avatar
Ben Gamari committed
23 24 25 26 27 28 29 30 31 32 33 34
        size <- getFileSize (root </> path)
        return $ Just $ DownloadFile { filePath = path
                                     , fileSize = size
                                     , fileSignature = if sig then Just sigPath else Nothing
                                     }
      | otherwise = return Nothing

main :: IO ()
main = do
    [root] <- getArgs
    files <- collectFiles root
    writeFile "files.index" (show files)