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

master2central december 2024 #1352

Merged
merged 10 commits into from
Dec 30, 2024
22 changes: 22 additions & 0 deletions .github/workflows/update-flake-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://github.com/DeterminateSystems/update-flake-lock
name: update-flake-lock
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '0 0 1 * *' # runs on first day of the month

jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@main
with:
pr-title: "Update flake.lock" # Title of PR to be created
pr-labels: | # Labels to be set on the PR
dependencies
automated
4 changes: 4 additions & 0 deletions datafiles/static/hackage.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ table {
font:100%;
}

pre {
border-radius: 3px;
}

pre, code, kbd, samp, .src {
font-family: monospace;
}
Expand Down
4 changes: 4 additions & 0 deletions datafiles/templates/Html/package-page.html.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<link href="$doc.baseUrl$/quick-jump.css" rel="stylesheet" type="text/css" title="QuickJump" />
$endif$
$hackageCssTheme()$
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/prism-solarizedlight.min.css" media="(prefers-color-scheme: light)" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/prism-tomorrow.min.css" media="(prefers-color-scheme: dark)" />
<title>
$package.name$$if(package.optional.hasSynopsis)$: $package.optional.synopsis$$endif$
</title>
Expand Down Expand Up @@ -293,6 +295,8 @@
[<a href="#description">back to package description</a>]
$package.optional.readme$
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/components/prism-core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/plugins/autoloader/prism-autoloader.min.js"></script>
$endif$
</div> <!-- /content -->

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
echo 'Copying packages from real Hackage Server into local Hackage Server.'
echo 'This assumes the local Hackage Server uses default credentials;'
echo 'otherwise, override in nix-default-servers.cfg'
hackage-mirror nix-default-servers.cfg
hackage-mirror nix-default-servers.cfg "$@"
'';
};
packages.default = config.packages.hackage-server;
Expand Down
18 changes: 10 additions & 8 deletions src/Distribution/Server/Features/Documentation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Distribution.Server.Framework.BlobStorage (BlobId)
import qualified Distribution.Server.Framework.BlobStorage as BlobStorage
import qualified Distribution.Server.Util.ServeTarball as ServerTarball
import qualified Distribution.Server.Util.DocMeta as DocMeta
import qualified Distribution.Server.Util.GZip as Gzip
import Distribution.Server.Features.BuildReports.BuildReport (PkgDetails(..), BuildStatus(..))
import Data.TarIndex (TarIndex)
import qualified Codec.Archive.Tar as Tar
Expand All @@ -46,7 +47,6 @@ import Data.Time.Clock (NominalDiffTime, diffUTCTime, getCurrentTime)
import System.Directory (getModificationTime)
import Control.Applicative
import Distribution.Server.Features.PreferredVersions
import Distribution.Server.Features.PreferredVersions.State (getVersionStatus)
import Distribution.Server.Packages.Types
-- TODO:
-- 1. Write an HTML view for organizing uploads
Expand Down Expand Up @@ -327,8 +327,10 @@ documentationFeature name
-- \* Generate the new index
-- \* Drop the index for the old tar-file
-- \* Link the new documentation to the package
fileContents <- expectUncompressedTarball
mres <- liftIO $ BlobStorage.addWith store fileContents
fileContents <- expectCompressedTarball
let filename = display pkgid ++ "-docs" <.> "tar.gz"
unpacked = Gzip.decompressNamed filename fileContents
mres <- liftIO $ BlobStorage.addWith store unpacked
(\content -> return (checkDocTarball pkgid content))
case mres of
Left err -> errBadRequest "Invalid documentation tarball" [MText err]
Expand Down Expand Up @@ -377,15 +379,15 @@ documentationFeature name
helper (pkg:pkgs) = do
hasDoc <- queryHasDocumentation (pkgInfoId pkg)
let status = getVersionStatus prefInfo (packageVersion pkg)
if hasDoc && status == NormalVersion
then pure (Just (packageId pkg))
if hasDoc && status == NormalVersion
then pure (Just (packageId pkg))
else helper pkgs

helper2 [] = pure Nothing
helper2 (pkg:pkgs) = do
hasDoc <- queryHasDocumentation (pkgInfoId pkg)
if hasDoc
then pure (Just (packageId pkg))
then pure (Just (packageId pkg))
else helper2 pkgs

withDocumentation :: Resource -> DynamicPath
Expand All @@ -400,7 +402,7 @@ documentationFeature name
then (var, unPackageName $ pkgName pkgid)
else e
| e@(var, _) <- dpath ]
basePkgPath = (renderResource' self basedpath)
basePkgPath = renderResource' self basedpath
canonicalLink = show serverBaseURI ++ basePkgPath
canonicalHeader = "<" ++ canonicalLink ++ ">; rel=\"canonical\""

Expand Down Expand Up @@ -484,7 +486,7 @@ checkDocTarball pkgid =
------------------------------------------------------------------------------}

mapParaM :: Monad m => (a -> m b) -> [a] -> m [(a, b)]
mapParaM f = mapM (\x -> (,) x `liftM` f x)
mapParaM f = mapM (\x -> (,) x <$> f x)

getFileAge :: FilePath -> IO NominalDiffTime
getFileAge file = diffUTCTime <$> getCurrentTime <*> getModificationTime file
4 changes: 3 additions & 1 deletion src/Distribution/Server/Features/PackageInfoJSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ initPackageInfoJSONFeature env = do
return $ \core preferred -> do

let coreR = coreResource core
info = "Get basic package information"
info = "Get basic package information: \
\The response contains a JSON object where the keys are version numbers as strings, \
\and the values are whether the version is preferred or not"
vInfo = "Get basic package information at a specific metadata revision"

jsonResources = [
Expand Down
12 changes: 1 addition & 11 deletions src/Distribution/Server/Framework/RequestContentTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Distribution.Server.Framework.RequestContentTypes (

-- * various specific content types
expectTextPlain,
expectUncompressedTarball,
expectCompressedTarball,
expectAesonContent,
expectCSV,
Expand Down Expand Up @@ -102,15 +101,6 @@ gzipDecompress content = go content decompressor
expectTextPlain :: ServerPartE LBS.ByteString
expectTextPlain = expectContentType "text/plain"

-- | Expect an uncompressed @.tar@ file.
--
-- The tar file is not validated.
--
-- A content-encoding of \"gzip\" is handled transparently.
--
expectUncompressedTarball :: ServerPartE LBS.ByteString
expectUncompressedTarball = expectContentType "application/x-tar"

-- | Expect a compressed @.tar.gz@ file.
--
-- Neither the gzip encoding nor the tar format are validated.
Expand All @@ -128,7 +118,7 @@ expectCompressedTarball = do
Just actual
| actual == "application/x-tar"
, contentEncoding == Just "gzip" -> consumeRequestBody
| actual == "application/x-gzip"
| actual == "application/gzip" || actual == "application/x-gzip"
, contentEncoding == Nothing -> consumeRequestBody
_ -> errExpectedTarball
where
Expand Down
4 changes: 3 additions & 1 deletion src/Distribution/Server/Packages/Unpack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ specVersionChecks specVerOk specVer = do
when (specVer < CabalSpecV1_2) $
throwError "'cabal-version' must be at least 1.2"

-- To keep people from uploading packages most users cannot use.
-- To keep people from uploading packages most users cannot use. Disabled for now.
{-
unless (specVer <= CabalSpecV3_6) $
throwError "'cabal-version' must be at most 3.6"
-}

-- | The issue is that browsers can upload the file name using either unix
-- or windows convention, so we need to take the basename using either
Expand Down
Loading