Commit 52e28b34 authored by Antoine Fontaine's avatar Antoine Fontaine 👣

Fix some warnings

it now compiles with `stack build --pedantic --ghc-options -Wno-name-shadowing`
parent 584a24b8
......@@ -7,11 +7,9 @@ import Protolude hiding (option)
import Control.Monad.Logger
import Database.Persist.Sqlite
import Data.Proxy (Proxy(..))
import Network.Wai.Handler.Warp (run)
import Options.Applicative
import qualified Data.Text as T
import Servant.API hiding (header)
import Servant.Server
import System.Directory
import System.Posix.Files (setFileMode)
......@@ -28,6 +26,7 @@ data Arguments = Args
}
-- argument parsing, see https://hackage.haskell.org/package/optparse-applicative
argParser :: Parser Arguments
argParser = Args
<$> option auto
( long "port"
......@@ -49,21 +48,24 @@ argParser = Args
( long "create-db"
<> help "Create (or update) database schemas instead of running" )
argParserInfo :: ParserInfo Arguments
argParserInfo = info (argParser <**> helper)
( fullDesc
<> header "gnupaste - gnugen's pastebin" )
runServer :: Arguments -> IO ()
runServer Args{..} = do
createDirectoryIfMissing True pasteDir
setFileMode pasteDir 0o700
db <- runStderrLoggingT $
createSqlitePool (T.pack sqlitePath) 1
forkIO $ cleanupPastes db (pasteDir<>"/")
_ <- forkIO $ cleanupPastes db (pasteDir<>"/")
let srv = server db (pasteDir<>"/")
pasteAPI = Proxy :: Proxy PasteAPI
application = serve pasteAPI srv
run port application
main :: IO ()
main = do
Args{..} <- execParser argParserInfo
let migrate = runSqlite (T.pack sqlitePath) $ do
......
......@@ -21,9 +21,6 @@ where
import Protolude
import Servant
import Servant.API.Header
import Servant.API.RemoteHost
import Servant.API.Verbs
import Servant.HTML.Blaze
import Servant.Multipart
import Text.Blaze.Html5
......
......@@ -26,7 +26,6 @@ import Protolude
import Paste.Utils
import Control.Concurrent
import qualified Data.Text as T
import Data.Time.Clock
import Database.Persist.Sql
......@@ -56,7 +55,7 @@ insertPaste = runSqlPool . insert_
generateHash :: ConnectionPool -- ^ The 'ConnectionPool' to the database.
-> IO Text
generateHash pool = do
hash <- forM [1 .. 4] . const $ pickElem pasteChars
hash <- forM [1 .. 4::Int] . const $ pickElem pasteChars
checkHash pool hash
-- Inner recursive function that appends a character upon each collision.
......@@ -64,7 +63,7 @@ generateHash pool = do
checkHash pool hash = do
mExists <- runSqlPool (selectFirst [PasteHash ==. T.pack hash] []) pool
case mExists of Nothing -> return $ T.pack hash
Just h -> pickElem pasteChars >>= checkHash pool . (: hash)
Just _ -> pickElem pasteChars >>= checkHash pool . (: hash)
-- | Function to cleanup expired pastes from the database and drive. Do not
-- call outside of the main loop: this function does not terminate!
......
......@@ -24,7 +24,6 @@ import Protolude
import Paste.API
import Paste.Database
import Paste.Homepage
import Paste.Utils
import qualified Data.Text as T
import Data.Time.Calendar
......@@ -33,7 +32,6 @@ import Database.Persist.Sql
import Network.Socket
import Servant
import Servant.Multipart
import Servant.Server
import System.Directory
import Text.Read
import Text.Regex
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment