mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
add check for directory existence during package version enumeration (#80)
* add check for directory existence during package version enumeration * cleanup * error consistency * errmsg cleanup
This commit is contained in:
@@ -76,7 +76,7 @@ getAppR file = do
|
||||
addPackageHeader pkg version
|
||||
void $ recordMetrics pkg version
|
||||
(len, src) <- getPackage pkg version >>= \case
|
||||
Nothing -> sendResponseStatus status404 ([i|#{pkg}@#{version} not found|] :: Text)
|
||||
Nothing -> sendResponseStatus status404 (NotFoundE [i|#{pkg}@#{version}|])
|
||||
Just a -> pure a
|
||||
addHeader "Content-Length" (show len)
|
||||
respondSource typeOctet $ src .| awaitForever sendChunkBS
|
||||
|
||||
@@ -96,7 +96,8 @@ import UnliftIO ( MonadUnliftIO
|
||||
)
|
||||
import UnliftIO ( tryPutMVar )
|
||||
import UnliftIO.Concurrent ( forkIO )
|
||||
import UnliftIO.Directory ( doesPathExist
|
||||
import UnliftIO.Directory ( doesDirectoryExist
|
||||
, doesPathExist
|
||||
, getFileSize
|
||||
, listDirectory
|
||||
, removeFile
|
||||
@@ -122,11 +123,16 @@ data PkgRepo = PkgRepo
|
||||
|
||||
getVersionsFor :: (MonadIO m, MonadReader r m, Has PkgRepo r, MonadLogger m) => PkgId -> m [Version]
|
||||
getVersionsFor pkg = do
|
||||
root <- asks pkgRepoFileRoot
|
||||
subdirs <- listDirectory $ root </> show pkg
|
||||
let (failures, successes) = partitionEithers $ (Atto.parseOnly parseVersion . T.pack) <$> subdirs
|
||||
for_ failures $ \f -> $logWarn [i|Emver Parse Failure for #{pkg}: #{f}|]
|
||||
pure successes
|
||||
root <- asks pkgRepoFileRoot
|
||||
let pkgDir = root </> show pkg
|
||||
exists <- doesDirectoryExist pkgDir
|
||||
if exists
|
||||
then do
|
||||
subdirs <- listDirectory pkgDir
|
||||
let (failures, successes) = partitionEithers $ (Atto.parseOnly parseVersion . T.pack) <$> subdirs
|
||||
for_ failures $ \f -> $logWarn [i|Emver Parse Failure for #{pkg}: #{f}|]
|
||||
pure successes
|
||||
else pure []
|
||||
|
||||
getViableVersions :: (MonadIO m, MonadReader r m, Has PkgRepo r, MonadLogger m) => PkgId -> VersionRange -> m [Version]
|
||||
getViableVersions pkg spec = filter (`satisfies` spec) <$> getVersionsFor pkg
|
||||
|
||||
Reference in New Issue
Block a user