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

Fix file+noindex URI usage on Windows #10728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jasagredo
Copy link
Collaborator

@jasagredo jasagredo commented Jan 8, 2025

This PR fixes the parsing of URIs for file+noindex repositories when using Windows paths. As suggested by @phadej in #10703 we now use (and specify in the docs) //./C:/... paths on Windows.

QA

In Windows, one can now specify //./ paths in file+noindex repositories. To check, create a simple package, then cabal sdist, move the tar.gz to some directory and in a different project declare the following stanza:

repository my-local-repo
  url: file+noindex:////./C:/path/to/repo

It might still fail because of #9891


Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • Manual QA notes have been included.
  • Tests have been added. (Ask for help if you don’t know how to write them! Ask for an exemption if tests are too complex for too little coverage!) fixing other tests failures seems like a good enough test for me

@jasagredo jasagredo force-pushed the js/local-noindex branch 3 times, most recently from 8cacda3 to fe6eed7 Compare January 9, 2025 00:44
@jasagredo jasagredo changed the title WIP fix local+noindex on Windows Fix file+noindex URI usage on Windows Jan 9, 2025
@jasagredo jasagredo marked this pull request as ready for review January 9, 2025 00:46
@jasagredo
Copy link
Collaborator Author

Notice this was broken on Windows #10095 (comment), see how the paths in the output do not have a C: component, because of what I described in the first code block of #10703

Cabal-syntax/src/Distribution/Utils/Path.hs Outdated Show resolved Hide resolved
Cabal-syntax/src/Distribution/Utils/Path.hs Outdated Show resolved Hide resolved
Copy link
Collaborator

@ulysses4ever ulysses4ever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I wonder if we can pull in some of Andrea’s PRs after this fix…

doc/config.rst Show resolved Hide resolved
changelog.d/pr-10728 Outdated Show resolved Hide resolved
@jasagredo jasagredo force-pushed the js/local-noindex branch 3 times, most recently from 390ce77 to 85d3807 Compare January 9, 2025 09:07
@jasagredo jasagredo force-pushed the js/local-noindex branch 2 times, most recently from a03d515 to 19c9a86 Compare January 9, 2025 10:09
changelog.d/pr-10728 Outdated Show resolved Hide resolved
@ulysses4ever
Copy link
Collaborator

Perhaps just inline it [asPosixPath]

I'd suggest not to inline it. I'd definitely prefer reading unrelated code that calls a function like that rather than seeing the list comprehension.

@jasagredo jasagredo requested a review from philderbeast January 9, 2025 16:43
@jasagredo jasagredo force-pushed the js/local-noindex branch 2 times, most recently from 908b17e to a48e96a Compare January 9, 2025 16:45
Cabal-syntax/src/Distribution/Utils/Path.hs Outdated Show resolved Hide resolved
Cabal-syntax/src/Distribution/Utils/Path.hs Outdated Show resolved Hide resolved
Cabal-syntax/src/Distribution/Utils/Path.hs Outdated Show resolved Hide resolved
@jasagredo jasagredo force-pushed the js/local-noindex branch 4 times, most recently from 6a9a53a to c7f0145 Compare January 9, 2025 17:42
@jasagredo
Copy link
Collaborator Author

Thanks for your thorough review @philderbeast !

@jasagredo jasagredo added merge me Tell Mergify Bot to merge and removed attention: needs-review labels Jan 9, 2025
@mergify mergify bot added the ready and waiting Mergify is waiting out the cooldown period label Jan 9, 2025
@philderbeast
Copy link
Collaborator

philderbeast commented Jan 9, 2025

@jasagredo, I checked the haddocks for Cabal-syntax and found a small rendering glitch:

image

I think this could be fixed with this patch:

$ git diff
diff --git a/Cabal-syntax/src/Distribution/Utils/Path.hs b/Cabal-syntax/src/Distribution/Utils/Path.hs
index fef2fe996..b082c17b5 100644
--- a/Cabal-syntax/src/Distribution/Utils/Path.hs
+++ b/Cabal-syntax/src/Distribution/Utils/Path.hs
@@ -545,7 +545,7 @@ data PkgConf
 
 -- | Sometimes we need to represent a Windows path (that might have been
 -- normalized) as a POSIX path, for example in URIs, as that is what
--- @network-uri@ understands. Furthermore they need to use the @\\.\@ DOS
+-- @network-uri@ understands. Furthermore they need to use the @\\\\.\\@ DOS
 -- device syntax or otherwise the filepath will be unusable.
 --
 -- >>> import Network.URI

@jasagredo
Copy link
Collaborator Author

jasagredo commented Jan 9, 2025

@philderbeast

Ah yes sounds familiar, see the first argument of https://hackage.haskell.org/package/Win32-2.14.1.0/docs/System-Win32-NamedPipes.html#v:createNamedPipe and the corresponding source code haddocks 😄

@jasagredo jasagredo removed merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period labels Jan 11, 2025
@jasagredo
Copy link
Collaborator Author

jasagredo commented Jan 11, 2025

I got an idea, but I won't be able to test it until tomorrow or maybe next week hence I'm removing the merge label.

My suspicion is that the path /C:/foo.txt if normalized to \C:\foo.txt can work too and we don't need the //./ syntax.

The basis for the suspicion is the NT namespace mentioned here

And if that is the case maybe I was wrong all along when thinking that network-uri fails to process Windows paths properly and file+noindex:///C:/some/path works if normalized.

@jasagredo
Copy link
Collaborator Author

OK I can confirm it does not work and my assumptions were right:

ghci> readFile "\\C:\\foo.txt"
*** Exception: \C:\foo.txt: openFile: invalid argument (Invalid argument)

In PowerShell:

Get-Content \C:\foo.txt
Get-Content: Cannot find drive. A drive with the name '\C' does not exist.

So the GHC documentation that mentions:

The namespaces are:

  • file namespace: \\?\
  • device namespace: \\.\
  • NT namespace: \

Seems wrong, as such an NT namespace does not seem usable.

@jasagredo jasagredo added merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period labels Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-backport 3.14 merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

file+noindex parsing is broken for Windows paths
3 participants