Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serving cabal files with package name in the file name. #1262

Merged
merged 1 commit into from Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafiles/templates/Html/revisions.html.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ stored separately.
</tr>
$revisions:{revision|
<tr>
<td valign="top"><a href="/package/$pkgid$/revision/$revision.number$.cabal">-r$revision.number$</a></td>
<td valign="top"><a href="/package/$pkgid$/revision/$revision.number$.cabal">-r$revision.number$</a> (<a href="/package/$pkgid$/revision/$pkgid$-$revision.number$.cabal">$pkgid$-r$revision.number$</a>)</td>
<td valign="top">$revision.htmltime$</td>
<td valign="top"><a href="/user/$revision.user$">$revision.user$</td>
<td valign="top">$revision.sha256$</th>
Expand Down
22 changes: 22 additions & 0 deletions src/Distribution/Server/Features/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ data CoreResource = CoreResource {
corePackageTarball :: Resource,
-- | A Cabal file metatada revision.
coreCabalFileRev :: Resource,
coreCabalFileRevName :: Resource,

-- Rendering resources.
-- | URI for `corePackagesPage`, given a format (blank for none).
Expand Down Expand Up @@ -403,6 +404,7 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
, coreCabalFile
, coreCabalFileRevs
, coreCabalFileRev
, coreCabalFileRevName
, coreUserDeauth
, coreAdminDeauth
, corePackUserDeauth
Expand Down Expand Up @@ -456,6 +458,11 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
resourceDesc = [(GET, "Get package .cabal file revision")]
, resourceGet = [("cabal", serveCabalFileRevision)]
}
coreCabalFileRevName = (resourceAt "/package/:package/revision/:tarball-:revision.:format") {
resourceDesc = [(GET, "Get package .cabal file revision with name")]
, resourceGet = [("cabal", serveCabalFileRevisionName)]
}


coreUserDeauth = (resourceAt "/packages/deauth") {
resourceDesc = [(GET, "Deauth Package user")]
Expand Down Expand Up @@ -750,6 +757,21 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
Nothing -> errNotFound "Package revision not found"
[MText "Cannot parse revision, or revision out of range."]

serveCabalFileRevisionName :: DynamicPath -> ServerPartE Response
serveCabalFileRevisionName dpath = do
pkgid1 <- packageTarballInPath dpath
pkgid2 <- packageInPath dpath
guard (pkgVersion pkgid2 == pkgVersion pkgid2)
pkginfo <- packageInPath dpath >>= lookupPackageId
let mrev = lookup "revision" dpath >>= fromReqURI
revisions = pkgMetadataRevisions pkginfo
case mrev >>= \rev -> revisions Vec.!? rev of
Just (fileRev, (utime, _uid)) -> return $ toResponse cabalfile
where
cabalfile = Resource.CabalFile (cabalFileByteString fileRev) utime
Nothing -> errNotFound "Package revision not found"
[MText "Cannot parse revision, or revision out of range."]


deauth :: DynamicPath -> ServerPartE Response
deauth _ = do
Expand Down