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

Unique filenames for $revision.cabal. #1261

Closed
ghost opened this issue Oct 26, 2023 · 7 comments · Fixed by #1262
Closed

Unique filenames for $revision.cabal. #1261

ghost opened this issue Oct 26, 2023 · 7 comments · Fixed by #1262

Comments

@ghost
Copy link

ghost commented Oct 26, 2023

Dear Haskell developers,

At the moment, versioned .cabal files are shipped under the name of $revision.cabal, e.g., 1.cabal. This makes it impossible to download many cabal files into a directory, because of the name clash.

Please, consider adding an url for the file with the name package-$revision.cabal.

Example:
In addition to having https://hackage.haskell.org/package/network-uri-2.6.4.2/revision/1.cabal, also add https://hackage.haskell.org/package/network-uri-2.6.4.2/revision/network-uri-2.6.4.2-1.cabal.

@ghost
Copy link
Author

ghost commented Oct 26, 2023

I think that something like that should be basically enough

diff --git a/datafiles/templates/Html/revisions.html.st b/datafiles/templates/Html/revisions.html.st
index 69cf2b75..f499d0ea 100644
--- a/datafiles/templates/Html/revisions.html.st
+++ b/datafiles/templates/Html/revisions.html.st
@@ -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>
diff --git a/src/Distribution/Server/Features/Core.hs b/src/Distribution/Server/Features/Core.hs
index 6aec793a..2247e771 100644
--- a/src/Distribution/Server/Features/Core.hs
+++ b/src/Distribution/Server/Features/Core.hs
@@ -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).
@@ -403,6 +404,7 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
           , coreCabalFile
           , coreCabalFileRevs
           , coreCabalFileRev
+          , coreCabalFileRevName
           , coreUserDeauth
           , coreAdminDeauth
           , corePackUserDeauth
@@ -456,6 +458,11 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
         resourceDesc = [(GET, "Get package .cabal file revision")]
       , resourceGet  = [("cabal", serveCabalFileRevision)]
       }
+    coreCabalFileRevName = (resourceAt "/package/:package/revision/:package-:revision.:format") {
+        resourceDesc = [(GET, "Get package .cabal file revision with name")]
+      , resourceGet  = [("cabal", serveCabalFileRevision)]
+      }
+
 
     coreUserDeauth = (resourceAt "/packages/deauth") {
         resourceDesc = [(GET,  "Deauth Package user")]

but I am not sure, I have never seen haskell before.

@andreabedini
Copy link
Contributor

@lockywolf Just out of curiosity, would you mind describing what leads you to download many cabal files for different packages by their revision number? Thanks

@ghost
Copy link
Author

ghost commented Oct 26, 2023

Yes. I am following the Cabal Manual section 3.1.3.2

https://cabal.readthedocs.io/en/3.6/installing-packages.html#local-no-index-repositories

My goal is to create a fully offline "vendored" build of a Haskell binary executable. I am doing "cabal fetch", as well as download the fixed-revision cabal files (so that they can be verified against an md5sum) into a "downloads" directory.

With this issue resolved, I can just feed the list of downloads into any download tool, like wget, and get a redistributable directory.

Then, on a disconnected machine, I am doing a local "noindex" repo, and run cabal install. The "noindex" repo requires the cabal files to be named as bar-0.2.0.0.cabal, but be of the revision which allows them to get correctly built offline.

The script can be found here:

https://gitlab.com/Lockywolf/lwfslackbuilds/-/blob/master/61_agda/agda/agda.SlackBuild?ref_type=heads

The tentative pull-request which resolves this issue can be found here:

#1262

@phadej
Copy link
Contributor

phadej commented Oct 26, 2023

I also find 1.cabal naming not very convenient. However, I have tools (and I'm sure there are others out there too) which use current URLs, so I'd kindly ask that old URLs are also preserved if new paths are added.

@andreabedini
Copy link
Contributor

@lockywolf in that case you only need one cabal file per package right?

Wouldn't be enough to grab that latest one from https://hackage.haskell.org/package/network-uri-2.6.4.2/network-uri.cabal?

In both cases you would still have to rename the file (a local repository expects network-uri-2.6.4.2.cabal) so I am not sure how the new path would improve the situation.

@ghost
Copy link
Author

ghost commented Oct 26, 2023

Wouldn't be enough to grab that latest one from

No, because with each update the md5 changes.

@andreabedini
Copy link
Contributor

andreabedini commented Oct 27, 2023

Thank you, I do understand the use-case better now but AFAIU you would still need to rename the file.

FWIW I put together a script for your use case (adapted from something similar I already had).

https://gist.github.com/andreabedini/79f20cf37a19fb78bbab8d0071999b23

@gbaz gbaz closed this as completed in #1262 Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants