apply hint suggestions

This commit is contained in:
Keagan McClelland
2022-05-23 13:23:54 -06:00
parent ae336445bd
commit bb8fe05db6
4 changed files with 19 additions and 21 deletions

View File

@@ -111,7 +111,7 @@ transitiveUpdate f = update (update @a @b f)
setWebProcessThreadId :: (ThreadId, ThreadId) -> RegistryCtx -> IO () setWebProcessThreadId :: (ThreadId, ThreadId) -> RegistryCtx -> IO ()
setWebProcessThreadId tid a = putMVar (appWebServerThreadId a) $ tid setWebProcessThreadId tid a = putMVar (appWebServerThreadId a) tid
-- This is where we define all of the routes in our application. For a full -- This is where we define all of the routes in our application. For a full
-- explanation of the syntax, please see: -- explanation of the syntax, please see:
@@ -173,11 +173,10 @@ instance Yesod RegistryCtx where
<> str <> str
) )
) )
<> (toLogStr <> toLogStr
(wrapSGRCode [SetColor Foreground Dull White] (wrapSGRCode [SetColor Foreground Dull White]
[i| @ #{loc_filename loc}:#{fst $ loc_start loc}\n|] [i| @ #{loc_filename loc}:#{fst $ loc_start loc}\n|]
) )
)
loggerPutStr logger formatted loggerPutStr logger formatted
where where
renderLvl lvl = case lvl of renderLvl lvl = case lvl of
@@ -242,4 +241,4 @@ unsafeHandler = Unsafe.fakeHandlerGetLogger appLogger
-- https://github.com/yesodweb/yesod/wiki/i18n-messages-in-the-scaffolding -- https://github.com/yesodweb/yesod/wiki/i18n-messages-in-the-scaffolding
appLogFunc :: RegistryCtx -> LogFunc appLogFunc :: RegistryCtx -> LogFunc
appLogFunc = appLogger >>= flip messageLoggerSource appLogFunc = appLogger <**> messageLoggerSource

View File

@@ -67,6 +67,7 @@ import Model
import Startlude ( ($) import Startlude ( ($)
, (&&) , (&&)
, (.) , (.)
, (/=)
, (<$>) , (<$>)
, Bool(..) , Bool(..)
, ByteString , ByteString
@@ -140,7 +141,7 @@ import Yesod.Core.Content ( typeGif
) )
import Yesod.Core.Types ( ContentType ) import Yesod.Core.Types ( ContentType )
data ManifestParseException = ManifestParseException FilePath newtype ManifestParseException = ManifestParseException FilePath
deriving Show deriving Show
instance Exception ManifestParseException instance Exception ManifestParseException
@@ -149,7 +150,7 @@ data PkgRepo = PkgRepo
, pkgRepoAppMgrBin :: FilePath , pkgRepoAppMgrBin :: FilePath
} }
data EosRepo = EosRepo newtype EosRepo = EosRepo
{ eosRepoFileRoot :: FilePath { eosRepoFileRoot :: FilePath
} }
@@ -161,7 +162,7 @@ getVersionsFor pkg = do
if exists if exists
then do then do
subdirs <- listDirectory pkgDir subdirs <- listDirectory pkgDir
let (failures, successes) = partitionEithers $ (Atto.parseOnly parseVersion . T.pack) <$> subdirs let (failures, successes) = partitionEithers $ Atto.parseOnly parseVersion . T.pack <$> subdirs
for_ failures $ \f -> $logWarn [i|Emver Parse Failure for #{pkg}: #{f}|] for_ failures $ \f -> $logWarn [i|Emver Parse Failure for #{pkg}: #{f}|]
pure successes pure successes
else pure [] else pure []
@@ -186,13 +187,11 @@ loadPkgDependencies appConnPool manifest = do
let deps' = first PkgRecordKey <$> HM.toList deps let deps' = first PkgRecordKey <$> HM.toList deps
for_ for_
deps' deps'
(\d -> (\d -> runSqlPool
(runSqlPool ( insertUnique
( insertUnique $ PkgDependency time (PkgRecordKey pkgId) pkgVersion (fst d) (packageDependencyVersion . snd $ d)
$ PkgDependency time (PkgRecordKey pkgId) pkgVersion (fst d) (packageDependencyVersion . snd $ d)
)
appConnPool
) )
appConnPool
) )
-- extract all package assets into their own respective files -- extract all package assets into their own respective files
@@ -232,7 +231,7 @@ extractPkg pool fp = handle @_ @SomeException cleanup $ do
$logError $ show e $logError $ show e
let pkgRoot = takeDirectory fp let pkgRoot = takeDirectory fp
fs <- listDirectory pkgRoot fs <- listDirectory pkgRoot
let toRemove = filter (not . (== ".s9pk") . takeExtension) fs let toRemove = filter ((/=) ".s9pk" . takeExtension) fs
mapConcurrently_ (removeFile . (pkgRoot </>)) toRemove mapConcurrently_ (removeFile . (pkgRoot </>)) toRemove
throwIO e throwIO e
@@ -295,7 +294,7 @@ getManifest pkg version = do
root <- asks pkgRepoFileRoot root <- asks pkgRepoFileRoot
let manifestPath = root </> show pkg </> show version </> "manifest.json" let manifestPath = root </> show pkg </> show version </> "manifest.json"
n <- getFileSize manifestPath n <- getFileSize manifestPath
pure $ (n, sourceFile manifestPath) pure (n, sourceFile manifestPath)
getInstructions :: (MonadResource m, MonadReader r m, Has PkgRepo r) getInstructions :: (MonadResource m, MonadReader r m, Has PkgRepo r)
=> PkgId => PkgId
@@ -305,7 +304,7 @@ getInstructions pkg version = do
root <- asks pkgRepoFileRoot root <- asks pkgRepoFileRoot
let instructionsPath = root </> show pkg </> show version </> "instructions.md" let instructionsPath = root </> show pkg </> show version </> "instructions.md"
n <- getFileSize instructionsPath n <- getFileSize instructionsPath
pure $ (n, sourceFile instructionsPath) pure (n, sourceFile instructionsPath)
getLicense :: (MonadResource m, MonadReader r m, Has PkgRepo r) getLicense :: (MonadResource m, MonadReader r m, Has PkgRepo r)
=> PkgId => PkgId
@@ -315,7 +314,7 @@ getLicense pkg version = do
root <- asks pkgRepoFileRoot root <- asks pkgRepoFileRoot
let licensePath = root </> show pkg </> show version </> "license.md" let licensePath = root </> show pkg </> show version </> "license.md"
n <- getFileSize licensePath n <- getFileSize licensePath
pure $ (n, sourceFile licensePath) pure (n, sourceFile licensePath)
getIcon :: (MonadResource m, MonadReader r m, Has PkgRepo r) getIcon :: (MonadResource m, MonadReader r m, Has PkgRepo r)
=> PkgId => PkgId
@@ -326,7 +325,7 @@ getIcon pkg version = do
let pkgRoot = root </> show pkg </> show version let pkgRoot = root </> show pkg </> show version
mIconFile <- find ((== "icon") . takeBaseName) <$> listDirectory pkgRoot mIconFile <- find ((== "icon") . takeBaseName) <$> listDirectory pkgRoot
case mIconFile of case mIconFile of
Nothing -> throwIO $ NotFoundE $ [i|#{pkg}: Icon|] Nothing -> throwIO $ NotFoundE [i|#{pkg}: Icon|]
Just x -> do Just x -> do
let ct = case takeExtension x of let ct = case takeExtension x of
".png" -> typePng ".png" -> typePng
@@ -336,7 +335,7 @@ getIcon pkg version = do
".gif" -> typeGif ".gif" -> typeGif
_ -> typePlain _ -> typePlain
n <- getFileSize (pkgRoot </> x) n <- getFileSize (pkgRoot </> x)
pure $ (ct, n, sourceFile (pkgRoot </> x)) pure (ct, n, sourceFile (pkgRoot </> x))
getHash :: (MonadIO m, MonadReader r m, Has PkgRepo r) => PkgId -> Version -> m ByteString getHash :: (MonadIO m, MonadReader r m, Has PkgRepo r) => PkgId -> Version -> m ByteString
getHash pkg version = do getHash pkg version = do

View File

@@ -61,7 +61,7 @@ instance ToJSONKey PkgId where
instance PersistField PkgId where instance PersistField PkgId where
toPersistValue = PersistText . show toPersistValue = PersistText . show
fromPersistValue (PersistText t) = Right . PkgId $ toS t fromPersistValue (PersistText t) = Right . PkgId $ toS t
fromPersistValue other = Left $ [i|Invalid AppId: #{other}|] fromPersistValue other = Left [i|Invalid AppId: #{other}|]
instance PersistFieldSql PkgId where instance PersistFieldSql PkgId where
sqlType _ = SqlString sqlType _ = SqlString
instance PathPiece PkgId where instance PathPiece PkgId where

View File

@@ -17,10 +17,10 @@ import Database.Persist ( PersistField(..)
import Database.Persist.Sql ( PersistFieldSql(..) ) import Database.Persist.Sql ( PersistFieldSql(..) )
import Startlude ( ($) import Startlude ( ($)
, (.) , (.)
, Bifunctor(bimap, first)
, ByteString , ByteString
, Either(Left) , Either(Left)
, Semigroup((<>)) , Semigroup((<>))
, bimap
, decodeUtf8 , decodeUtf8
, encodeUtf8 , encodeUtf8
, join , join