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 SVN downloads of versioned formula by munging directory names #4358

Merged
merged 1 commit into from
Jun 25, 2018
Merged

Fix SVN downloads of versioned formula by munging directory names #4358

merged 1 commit into from
Jun 25, 2018

Conversation

apjanke
Copy link
Contributor

@apjanke apjanke commented Jun 20, 2018

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

The SubversionDownloadStrategy is broken for versioned formulae, because it includes an "@" in the resulting directory names, and "@" is a special character to Subversion. This PR fixes it by munging the cache and staging directory names to use "_AT_" instead of "@", avoiding the special character.

There's currently no test for the SubversionDownloadStrategy, and it doesn't look like download strategies are tested in the context of a stage operation. Suggestions welcome as to how to do a decent test on this.

Details

To reproduce, create a versioned formula that uses an SVN download as its main download, for example, netpbm. Do a brew install -s on it, and it'll error during the fetch step.

$ brew install -s octave-app/octave-app/[email protected]                                                                                                                                                      master
==> Installing [email protected] from octave-app/octave-app
==> Cloning svn://svn.code.sf.net/p/netpbm/code/stable
Updating /Users/janke/Library/Caches/Homebrew/[email protected]
==> Checking out 3244
svn: E200009: '/Users/janke/Library/Caches/Homebrew/[email protected]': a peg revision is not allowed here
Error: Failed to download resource "[email protected]"
Failure while executing: svn up -q /Users/janke/Library/Caches/Homebrew/[email protected] -r 3244

References

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Nice work!

@@ -665,6 +665,11 @@ def initialize(name, resource)
@url = @url.sub("svn+http://", "")
end

def cache_filename
# "@" is a special character for Subversion. Keep it out of the cache dir name.
"#{name.gsub("@", "_AT_")}--#{cache_tag}"
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we need the _? I also wonder about using - instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to -. I like having some separator there for readability.

@@ -67,7 +67,8 @@ def escaped_name
end

def download_name
name.nil? ? owner.name : "#{owner.name}--#{escaped_name}"
# Must not have "@" in download_name because it's a special character to Subversion
(name.nil? ? owner.name : "#{owner.name}--#{escaped_name}").gsub("@", "_AT_")
Copy link
Member

Choose a reason for hiding this comment

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

if name would be a bit nicer (I know it's not your code). Would be good to reuse the gsub; perhaps a shared resource function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored it to use an if name.

@apjanke
Copy link
Contributor Author

apjanke commented Jun 23, 2018

Ping! Any outstanding changes still needed on this? Would be nice to get this merged, since I'm actively encountering this error in a project.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Sorry I had an unsubmitted review and am on vacation with spotty internet.

@@ -665,6 +665,11 @@ def initialize(name, resource)
@url = @url.sub("svn+http://", "")
end

def cache_filename
# "@" is a special character for Subversion. Keep it out of the cache dir name.
"#{name.gsub("@", "-AT-")}--#{cache_tag}"
Copy link
Member

Choose a reason for hiding this comment

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

Can the .gsub("@", "-AT-") go into a function somewhere rather than duplicating below? Note that below the duplication is not correct too 😉

@apjanke
Copy link
Contributor Author

apjanke commented Jun 24, 2018

No worries. Enjoy your vacation; this stuff can wait!

When you have time, I've pushed an amendment with a refactor that addresses your latest comments, consolidating the gsub into a single shared method.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Brew style is failing

@@ -665,6 +665,11 @@ def initialize(name, resource)
@url = @url.sub("svn+http://", "")
end

def cache_filename
# "@" is a special character for Subversion. Keep it out of the cache dir name.
Copy link
Member

Choose a reason for hiding this comment

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

Feels like this comment should be for safe download name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved comment to safe_download_name.

Resource.safe_download_name(
if name
"#{owner.name}--#{escaped_name}"
else
Copy link
Member

Choose a reason for hiding this comment

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

Feels weird having an if inside a function call. I’d assign a new variable outside it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote it to use a temporary variable. Moved & merged comment to safe_download_name.

@apjanke
Copy link
Contributor Author

apjanke commented Jun 25, 2018

Amended to address comments; brew style fixed.

@@ -727,6 +727,7 @@ def build

formula.update_head_version

puts "Testing formula prefix for emptiness: formula.prefix='#{formula.prefix}'"
Copy link
Member

Choose a reason for hiding this comment

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

Oops

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Fixed.

Sorry for all the hassle here.

@MikeMcQuaid MikeMcQuaid merged commit 7506abe into Homebrew:master Jun 25, 2018
@MikeMcQuaid
Copy link
Member

Thanks @apjanke!

@apjanke apjanke deleted the fix-subversion-download-of-versioned-formulae branch June 25, 2018 08:05
@apjanke
Copy link
Contributor Author

apjanke commented Jun 25, 2018

Yay, thank you! And you're welcome!

apjanke added a commit to octave-app/octave-app-bundler that referenced this pull request Jun 25, 2018
Homebrew/brew#4358 fixes downloads of versioned
formulae from SVN repos, and is in master Homebrew now. No need for
our special patch branch any more.
@ilovezfs
Copy link
Contributor

This seems to have changed the URLs that brew mirror uses for @ formulae.

Before revert:

iMac-TMP:Homebrew joe$ brew mirror imagemagick@6
==> Downloading https://dl.bintray.com/homebrew/mirror/imagemagick%406-6.9.10-3.tar.xz
Already downloaded: /Users/joe/Library/Caches/Homebrew/imagemagick-AT-6-6.9.10-3.tar.xz
==> Uploading to https://dl.bintray.com/homebrew/mirror/imagemagick-AT-6-6.9.10-3.tar.xz
^C

After revert:

iMac-TMP:Homebrew joe$ brew mirror imagemagick@6
==> Downloading https://dl.bintray.com/homebrew/mirror/imagemagick%406-6.9.10-3.tar.xz
Already downloaded: /Users/joe/Library/Caches/Homebrew/[email protected]
==> Uploading to https://dl.bintray.com/homebrew/mirror/[email protected]

CC @apjanke

@apjanke
Copy link
Contributor Author

apjanke commented Jun 25, 2018

Darn it!

Do the file upload names to Bintray matter? If so, best revert this PR, and I'll have to come up with a more detailed PR that tracks both original filenames and local filenames separately.

@MikeMcQuaid
Copy link
Member

I’d suggest tracking or calculating the original url filename in mirror as that’ll be the only place this matters.

@ilovezfs
Copy link
Contributor

Do the file upload names to Bintray matter?

mirror "https://dl.bintray.com/homebrew/mirror/imagemagick-AT-6-6.9.10-3.tar.xz"

should work if the change is intentional.

Personally, I'm really unconvinced that having the @ formula names in the cache files be munged just for the sake of svn was a desirable change. Hunting for

[email protected]
gcc@7--patch-863957f90a934ee8f89707980473769cff47ca0663c3906992da6afb242fb220.patch

is a lot nicer than
gcc-AT-7-7.3.0.tar.xz
gcc-AT-7--patch-863957f90a934ee8f89707980473769cff47ca0663c3906992da6afb242fb220.patch

Also does this invalidate cleanup? Is it still going to know how to cleanup the tarballs with the old names or did they all just get stranded forever?

@MikeMcQuaid
Copy link
Member

I didn’t review this sufficiently. I was under the impression from the PR description that this only affected SVN resources. I think it should be reverted and scoped just to them, unfortunately.

@apjanke
Copy link
Contributor Author

apjanke commented Jun 27, 2018

Okay, sorry. I will re-submit a new PR scoped only to SVN downloads when I'm able to figure out how to properly unit test it.

@lock lock bot added the outdated PR was locked due to age label Jul 27, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants