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

Add command fails on windows #6

Open
wvdvegt opened this issue Sep 17, 2020 · 8 comments
Open

Add command fails on windows #6

wvdvegt opened this issue Sep 17, 2020 · 8 comments

Comments

@wvdvegt
Copy link

wvdvegt commented Sep 17, 2020

When I try to add twig using

perseus add "twig/twig"

I get a warning

Failed to retrieve information about package "twig/twig" from Packagist. Called https://packagist.org/packages%5Ctwig%5Ctwig.json. Error: Expected a return code within 2xx for package "twig/twig". Got 404

It seems that the %5C escapes are not accepted by packagist anymore as

https://packagist.org/packages%5Ctwig%5Ctwig.json

returns the requested json

Expected Behavior

Should just work

Current Behavior

Fails to retrieve the package description.

Possible Solution

Steps to Reproduce (for bugs)

  1. run perseus add "twig/twig" on windows.

Context

Your Environment

  • Version used (perseus version):
  • Operating System and version:
  • Medusa configuration:
  • Satis configuration:
@andygrunwald
Copy link
Owner

Hey @wvdvegt,
thanks for raising this issue. Indeed, I never tested it on windows.
Would you be open to testing it further, try to fix this one and send a Pull Request? This would help a lot.
Let me know what you think.

@wvdvegt
Copy link
Author

wvdvegt commented Sep 22, 2020

Hi,

I do not have go installed nor have experience with it, but i might try if i have some spare time. Always ready to learn.

@andygrunwald
Copy link
Owner

Sounds great. Let me know how I can help or guide you a bit.

@wvdvegt
Copy link
Author

wvdvegt commented Sep 23, 2020

I Installed GO and tried to follow your 'from source' installation script (on Windows). Some remarks:

  1. $GOPATH needs to be replaced by %GOPATH% to work.
  2. The path in the line
    cd "%GOPATH%/src/github.com/andygrunwald/perseus"
    needs to be quoted (note that Windows happily accepts \ and / in a path).
  3. After some fiddling I got the 3rd line to work (added -v switch for some output)
  4. This one fails, which 'make' is used?

@wvdvegt
Copy link
Author

wvdvegt commented Sep 23, 2020

I mostly get

no Go files in C:\Users\xxx\go\src\github.com\andygrunwald\perseus

type of errors when I run go install.

@wvdvegt
Copy link
Author

wvdvegt commented Sep 23, 2020

Hi
Got it running under Visual Studio Code.

In dependency/repository/packagist.go the lines:

// GetPackageByName returns a package by a given name
func (c *PackagistClient) GetPackageByName(name string) (*PackagistPackage, *http.Response, error) {
	u := fmt.Sprintf("%s/packages%s.json", c.url.String(), filepath.Clean("/"+name))

should be changed to:

// GetPackageByName returns a package by a given name
func (c *PackagistClient) GetPackageByName(name string) (*PackagistPackage, *http.Response, error) {
	u := fmt.Sprintf("%s/packages/%s.json", c.url.String(), name)

to at least get it downloading (not sure if it totally works).

The main issue is that filePath.Clean() method seems to replace all / and \ by the operating system's directory separator char (so the original /twig/twig gets changed into \twig\twig resulting in %5C escape codes in the url. Think it's caused by using a file path method on a url segment.

Something as

u := fmt.Sprintf("%s/packages%s.json", c.url.String(), strings.Replace(filepath.Clean("/"+name), "\\", "/", -1))

might also do the trick. It leaves the Clean() in place but flips the slashes back into url mode.

Maybe it needs to be changed on some more spots in the code.

@andygrunwald
Copy link
Owner

@wvdvegt Sounds reasonable. Thanks for the investigation so far.
Would you be open to create a Pull Request with the adjustments?

Thanks!

@wvdvegt
Copy link
Author

wvdvegt commented Sep 28, 2020 via email

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

No branches or pull requests

2 participants