Skip to content

Commit 71f0c37

Browse files
Edouard-chinhsbt
authored andcommitted
[rubygems/rubygems] Modify bundle doctor to not report issue when files aren't writable:
- ### Problem Running `bundle doctor` warn about files that aren't writable. This makes the output of `bundle doctor` very verbose for something I believe isn't really an issue. ### Context Rubygems keeps the files original permission at the time the gem is packaged. Many gem maintainers have decided that the permissions of the files in their bundled would be 0444, this includes amongst others: minitest, selenium, brakeman... Any git gems that had a 0444 permissions at some point in its git history would also be reported (as bundle doctor look in the `cache/bundler/git/<gem>/object` path). While it completely make sense to report when files aren't readable, maybe it's worth questioning the usefulness of reporting files that can't be written and what problem this causes to the user (if any). ### Solution Removed the check for unwritable file. ### Side note I also tweaked the "No issues ..." message logic as it was doing the opposite (reporting an issue when there is none and vice versa). This wasn't caught in tests because as a stub on `Bundler.ui.info` was missing. ruby/rubygems@9a426b9495
1 parent b7c87cc commit 71f0c37

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

lib/bundler/cli/doctor.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def run
9999
end
100100
end.sort.each {|m| message += m }
101101
raise ProductionError, message
102-
elsif !permissions_valid
102+
elsif permissions_valid
103103
Bundler.ui.info "No issues found with the installed bundle"
104104
end
105105
end
@@ -108,21 +108,21 @@ def run
108108

109109
def check_home_permissions
110110
require "find"
111-
files_not_readable_or_writable = []
112-
files_not_rw_and_owned_by_different_user = []
113-
files_not_owned_by_current_user_but_still_rw = []
111+
files_not_readable = []
112+
files_not_readable_and_owned_by_different_user = []
113+
files_not_owned_by_current_user_but_still_readable = []
114114
broken_symlinks = []
115115
Find.find(Bundler.bundle_path.to_s).each do |f|
116116
if !File.exist?(f)
117117
broken_symlinks << f
118-
elsif !File.writable?(f) || !File.readable?(f)
118+
elsif !File.readable?(f)
119119
if File.stat(f).uid != Process.uid
120-
files_not_rw_and_owned_by_different_user << f
120+
files_not_readable_and_owned_by_different_user << f
121121
else
122-
files_not_readable_or_writable << f
122+
files_not_readable << f
123123
end
124124
elsif File.stat(f).uid != Process.uid
125-
files_not_owned_by_current_user_but_still_rw << f
125+
files_not_owned_by_current_user_but_still_readable << f
126126
end
127127
end
128128

@@ -134,23 +134,23 @@ def check_home_permissions
134134
ok = false
135135
end
136136

137-
if files_not_owned_by_current_user_but_still_rw.any?
137+
if files_not_owned_by_current_user_but_still_readable.any?
138138
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
139-
"user, but are still readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}"
139+
"user, but are still readable. These files are:\n - #{files_not_owned_by_current_user_but_still_readable.join("\n - ")}"
140140

141141
ok = false
142142
end
143143

144-
if files_not_rw_and_owned_by_different_user.any?
144+
if files_not_readable_and_owned_by_different_user.any?
145145
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
146-
"user, and are not readable/writable. These files are:\n - #{files_not_rw_and_owned_by_different_user.join("\n - ")}"
146+
"user, and are not readable. These files are:\n - #{files_not_readable_and_owned_by_different_user.join("\n - ")}"
147147

148148
ok = false
149149
end
150150

151-
if files_not_readable_or_writable.any?
151+
if files_not_readable.any?
152152
Bundler.ui.warn "Files exist in the Bundler home that are not " \
153-
"readable/writable by the current user. These files are:\n - #{files_not_readable_or_writable.join("\n - ")}"
153+
"readable by the current user. These files are:\n - #{files_not_readable.join("\n - ")}"
154154

155155
ok = false
156156
end

spec/bundler/commands/doctor_spec.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@stdout = StringIO.new
1616

17-
[:error, :warn].each do |method|
17+
[:error, :warn, :info].each do |method|
1818
allow(Bundler.ui).to receive(method).and_wrap_original do |m, message|
1919
m.call message
2020
@stdout.puts message
@@ -45,20 +45,20 @@
4545
allow(File).to receive(:writable?).with(File.expand_path("..", Gem.default_dir))
4646
end
4747

48-
it "exits with no message if the installed gem has no C extensions" do
48+
it "exits with a success message if the installed gem has no C extensions" do
4949
doctor = Bundler::CLI::Doctor.new({})
5050
allow(doctor).to receive(:lookup_with_fiddle).and_return(false)
5151
expect { doctor.run }.not_to raise_error
52-
expect(@stdout.string).to be_empty
52+
expect(@stdout.string).to include("No issues")
5353
end
5454

55-
it "exits with no message if the installed gem's C extension dylib breakage is fine" do
55+
it "exits with a success message if the installed gem's C extension dylib breakage is fine" do
5656
doctor = Bundler::CLI::Doctor.new({})
5757
expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"]
5858
expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"]
5959
allow(doctor).to receive(:lookup_with_fiddle).with("/usr/lib/libSystem.dylib").and_return(false)
6060
expect { doctor.run }.not_to raise_error
61-
expect(@stdout.string).to be_empty
61+
expect(@stdout.string).to include("No issues")
6262
end
6363

6464
it "exits with a message if one of the linked libraries is missing" do
@@ -105,19 +105,32 @@
105105
allow(File).to receive(:stat).with(@unwritable_file) { @stat }
106106
end
107107

108-
it "exits with an error if home contains files that are not readable/writable" do
108+
it "exits with an error if home contains files that are not readable" do
109109
doctor = Bundler::CLI::Doctor.new({})
110110
allow(doctor).to receive(:lookup_with_fiddle).and_return(false)
111111
allow(@stat).to receive(:uid) { Process.uid }
112112
allow(File).to receive(:writable?).with(@unwritable_file) { false }
113113
allow(File).to receive(:readable?).with(@unwritable_file) { false }
114114
expect { doctor.run }.not_to raise_error
115115
expect(@stdout.string).to include(
116-
"Files exist in the Bundler home that are not readable/writable by the current user. These files are:\n - #{@unwritable_file}"
116+
"Files exist in the Bundler home that are not readable by the current user. These files are:\n - #{@unwritable_file}"
117117
)
118118
expect(@stdout.string).not_to include("No issues")
119119
end
120120

121+
it "exits without an error if home contains files that are not writable" do
122+
doctor = Bundler::CLI::Doctor.new({})
123+
allow(doctor).to receive(:lookup_with_fiddle).and_return(false)
124+
allow(@stat).to receive(:uid) { Process.uid }
125+
allow(File).to receive(:writable?).with(@unwritable_file) { false }
126+
allow(File).to receive(:readable?).with(@unwritable_file) { true }
127+
expect { doctor.run }.not_to raise_error
128+
expect(@stdout.string).not_to include(
129+
"Files exist in the Bundler home that are not readable by the current user. These files are:\n - #{@unwritable_file}"
130+
)
131+
expect(@stdout.string).to include("No issues")
132+
end
133+
121134
context "when home contains files that are not owned by the current process", :permissions do
122135
before(:each) do
123136
allow(@stat).to receive(:uid) { 0o0000 }
@@ -130,7 +143,7 @@
130143
allow(File).to receive(:readable?).with(@unwritable_file) { false }
131144
expect { doctor.run }.not_to raise_error
132145
expect(@stdout.string).to include(
133-
"Files exist in the Bundler home that are owned by another user, and are not readable/writable. These files are:\n - #{@unwritable_file}"
146+
"Files exist in the Bundler home that are owned by another user, and are not readable. These files are:\n - #{@unwritable_file}"
134147
)
135148
expect(@stdout.string).not_to include("No issues")
136149
end
@@ -142,7 +155,7 @@
142155
allow(File).to receive(:readable?).with(@unwritable_file) { true }
143156
expect { doctor.run }.not_to raise_error
144157
expect(@stdout.string).to include(
145-
"Files exist in the Bundler home that are owned by another user, but are still readable/writable. These files are:\n - #{@unwritable_file}"
158+
"Files exist in the Bundler home that are owned by another user, but are still readable. These files are:\n - #{@unwritable_file}"
146159
)
147160
expect(@stdout.string).not_to include("No issues")
148161
end

0 commit comments

Comments
 (0)