Check correct paths are writable in requires_sudo?#6318
Check correct paths are writable in requires_sudo?#6318bundlerbot merged 2 commits intorubygems:masterfrom
Conversation
|
Thanks for opening a pull request and helping make Bundler better! Someone from the Bundler team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality. We use Travis CI to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of Travis CI in the PR status window below. If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #bundler channel on Slack. For more information about contributing to the Bundler project feel free to review our CONTRIBUTING guide |
|
Thanks for the PR! Could you please look into adding a test for this fix? |
|
ping @jhawthorn |
97d1afd to
6b23ad6
Compare
|
@segiddins @colby-swandale I finally got around to this. There are now specs for the basic behaviour of EDIT: I don't believe failures are related |
segiddins
left a comment
There was a problem hiding this comment.
Thanks! We'll look into fixing those failures on master, then we'll just be able to 👍 and merge
| allow(Bundler).to receive(:which).with("sudo").and_return("/usr/bin/sudo") | ||
|
|
||
| require "tmpdir" | ||
| @tmpdir = Dir.mktmpdir |
There was a problem hiding this comment.
please use let instead of ivars
This previously had no specs
This method's goal is to check that bundle_path, and directories that bundler may need to write within it are writable. If bundle_path itself does not exist, we instead find the nearest existent parent directory, and check that that exists. However these two rules were combined incorrectly. If bundle_path did not exist, bundler would check that the nearest parent directory _and everything within that parent directory_ were writable. This could lead to false positives for requires_sudo? when bundle_path did not yet exist. This commit fixes the issue by always checking the writability of $bundle_path/* instead of $parent_path/*.
6b23ad6 to
d8bb345
Compare
|
Thanks! @bundlerbot r+ |
|
📌 Commit d8bb345 has been approved by |
…r=segiddins Check correct paths are writable in requires_sudo? ### What was the end-user problem that led to this PR? Bundler was attempting to use `sudo`, despite having permissions to create `bundle_path` (which didn't yet exist). For some reason this became an issue in recent versions of bundler, where it wasn't one before. I'm not sure what change caused this problem to be exposed since `requires_sudo?` has not changed in a while. ### What was your diagnosis of the problem? `requires_sudo?` checks that bundle_path, and directories that bundler may need to write within it are writable. If bundle_path itself does not exist, we instead find the nearest existent parent directory, and check that that exists. Unfortunately, when these two rules were applied together, we got the wrong result. If `bundle_path` did not exist, bundler would check that the nearest parent directory **and everything within that parent directory** were writable. This could lead to false positives for `requires_sudo?` when `bundle_path` did not yet exist. ### What is your fix for the problem, implemented in this PR? This commit fixes the issue by always checking the writability of `$bundle_path/*` instead of `$parent_path/*`. ### Why did you choose this fix out of the possible options? If we are able to create `bundle_path`, we know that we can write to anything within it. Changing the test to use `Dir["$bundle_path/*"]` is a succinct way to implement this since it will return `[]` if `bundle_path` does not yet exist.
|
☀️ Test successful - status-travis |
…r=segiddins Check correct paths are writable in requires_sudo? Bundler was attempting to use `sudo`, despite having permissions to create `bundle_path` (which didn't yet exist). For some reason this became an issue in recent versions of bundler, where it wasn't one before. I'm not sure what change caused this problem to be exposed since `requires_sudo?` has not changed in a while. `requires_sudo?` checks that bundle_path, and directories that bundler may need to write within it are writable. If bundle_path itself does not exist, we instead find the nearest existent parent directory, and check that that exists. Unfortunately, when these two rules were applied together, we got the wrong result. If `bundle_path` did not exist, bundler would check that the nearest parent directory **and everything within that parent directory** were writable. This could lead to false positives for `requires_sudo?` when `bundle_path` did not yet exist. This commit fixes the issue by always checking the writability of `$bundle_path/*` instead of `$parent_path/*`. If we are able to create `bundle_path`, we know that we can write to anything within it. Changing the test to use `Dir["$bundle_path/*"]` is a succinct way to implement this since it will return `[]` if `bundle_path` does not yet exist. (cherry picked from commit 9487710)
…r=segiddins Check correct paths are writable in requires_sudo? ### What was the end-user problem that led to this PR? Bundler was attempting to use `sudo`, despite having permissions to create `bundle_path` (which didn't yet exist). For some reason this became an issue in recent versions of bundler, where it wasn't one before. I'm not sure what change caused this problem to be exposed since `requires_sudo?` has not changed in a while. ### What was your diagnosis of the problem? `requires_sudo?` checks that bundle_path, and directories that bundler may need to write within it are writable. If bundle_path itself does not exist, we instead find the nearest existent parent directory, and check that that exists. Unfortunately, when these two rules were applied together, we got the wrong result. If `bundle_path` did not exist, bundler would check that the nearest parent directory **and everything within that parent directory** were writable. This could lead to false positives for `requires_sudo?` when `bundle_path` did not yet exist. ### What is your fix for the problem, implemented in this PR? This commit fixes the issue by always checking the writability of `$bundle_path/*` instead of `$parent_path/*`. ### Why did you choose this fix out of the possible options? If we are able to create `bundle_path`, we know that we can write to anything within it. Changing the test to use `Dir["$bundle_path/*"]` is a succinct way to implement this since it will return `[]` if `bundle_path` does not yet exist. (cherry picked from commit 9487710)
* 1-17-stable: (38 commits) Version 1.17.0 with changelog Merge #6754 Version 1.17.0.pre.2 with changelog fix failing bundle remove specs Still document the `--force` option scope specs testing bundler 2 deprecations to bundler 1 only Merge #6718 Merge #6707 Merge #6702 Merge #6316 Auto merge of #6447 - agrim123:agr-update-error-message, r=segiddins Auto merge of #6513 - agrim123:agr-bundler-remove, r=indirect Auto merge of #6318 - jhawthorn:fix_incorrect_test_in_requires_sudo, r=segiddins Auto merge of #6450 - bundler:segiddins/bundle-binstubs-all, r=colby-swandale Auto merge of #6024 - gwerbin:custom-user-bundle-dir, r=colby-swandale Version 1.17.0.pre.1 with changelog Auto merge of #5964 - bundler:colby/deprecate-viz-command, r=segiddins Auto merge of #5986 - bundler:seg-jobs-count, r=indirect Auto merge of #5995 - bundler:seg-gvp-major, r=indirect Auto merge of #5803 - igorbozato:path_relative_to_pwd, r=indirect ...
What was the end-user problem that led to this PR?
Bundler was attempting to use
sudo, despite having permissions to createbundle_path(which didn't yet exist).For some reason this became an issue in recent versions of bundler, where it wasn't one before. I'm not sure what change caused this problem to be exposed since
requires_sudo?has not changed in a while.What was your diagnosis of the problem?
requires_sudo?checks that bundle_path, and directories that bundler may need to write within it are writable. If bundle_path itself does not exist, we instead find the nearest existent parent directory, and check that that exists.Unfortunately, when these two rules were applied together, we got the wrong result. If
bundle_pathdid not exist, bundler would check that the nearest parent directory and everything within that parent directory were writable. This could lead to false positives forrequires_sudo?whenbundle_pathdid not yet exist.What is your fix for the problem, implemented in this PR?
This commit fixes the issue by always checking the writability of
$bundle_path/*instead of$parent_path/*.Why did you choose this fix out of the possible options?
If we are able to create
bundle_path, we know that we can write to anything within it. Changing the test to useDir["$bundle_path/*"]is a succinct way to implement this since it will return[]ifbundle_pathdoes not yet exist.