diff --git a/Handler/CreateChallenge.hs b/Handler/CreateChallenge.hs index d1d5eb7..e296377 100644 --- a/Handler/CreateChallenge.hs +++ b/Handler/CreateChallenge.hs @@ -127,10 +127,13 @@ updateTests challengeId chan = do msg chan (T.pack $ show testDirs) return () +expectedFileName :: FilePath expectedFileName = "expected.tsv" doesExpectedExist :: FilePath -> IO Bool -doesExpectedExist fp = doesFileExist (fp expectedFileName) +doesExpectedExist fp = do + ef <- findFilePossiblyCompressed (fp expectedFileName) + return $ isJust ef checkTestDir :: Channel -> (Key Challenge) -> Challenge -> SHA1 -> FilePath -> Handler () checkTestDir chan challengeId challenge commit testDir = do diff --git a/Handler/Shared.hs b/Handler/Shared.hs index 6a84fdb..1b3cfd1 100644 --- a/Handler/Shared.hs +++ b/Handler/Shared.hs @@ -24,7 +24,7 @@ import qualified Data.List as DL import System.Random -import System.Directory (renameDirectory) +import System.Directory (doesFileExist, renameDirectory) import PersistSHA1 @@ -331,3 +331,11 @@ formatTruncatedScore _ Nothing = formatFullScore Nothing formatTruncatedScore (Just precision) (Just evaluation) = case evaluationScore evaluation of Just score -> T.pack $ printf "%0.*f" precision score Nothing -> formatFullScore Nothing + +findFilePossiblyCompressed :: FilePath -> IO (Maybe FilePath) +findFilePossiblyCompressed baseFilePath = do + let possibleFiles = [baseFilePath] ++ (map (baseFilePath <.>) ["gz", "bz2", "xz"]) + foundFiles <- filterM doesFileExist possibleFiles + return $ case foundFiles of + [] -> Nothing + (h:_) -> Just h diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index 7373e9e..35b1bfe 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -9,7 +9,6 @@ import Data.Monoid import qualified Data.Text.Lazy as TL import Text.Markdown -import System.Directory (doesFileExist) import qualified Data.Text as T import qualified Yesod.Table as Table @@ -289,11 +288,7 @@ getOutFilePath repoDir test = repoDir (T.unpack $ testName test) outFile findOutFile repoDir test = do let baseOut = getOutFilePath repoDir test - let possibleOuts = [baseOut] ++ (map (baseOut <.>) ["gz", "bz2", "xz"]) - foundFiles <- filterM doesFileExist possibleOuts - return $ case foundFiles of - [] -> Nothing - (h:_) -> Just h + findFilePossiblyCompressed baseOut doesOutExist repoDir (Entity _ test) = do result <- findOutFile repoDir test diff --git a/gonito.cabal b/gonito.cabal index 97ac36b..9a9a19a 100644 --- a/gonito.cabal +++ b/gonito.cabal @@ -122,7 +122,7 @@ library , filemanip , cryptohash , markdown - , geval >= 0.5.0.0 + , geval >= 1.0.0.0 , filepath , yesod-table , regex-tdfa