Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Add check of Dir.home's permission #4886

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def self.start(*)
raise e
ensure
Bundler::SharedHelpers.print_major_deprecations!
Bundler::SharedHelpers.check_home_dir_permissions
end

def self.dispatch(*)
Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def print_major_deprecations!
major_deprecation("Bundler will only support rubygems >= 2.0, you are running #{Bundler.rubygems.version}")
end

def check_home_dir_permissions
raise PathError, "There was an error while trying to use your home path #{Dir.home}" unless File.writable?(Dir.home)
Copy link
Member

Choose a reason for hiding this comment

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

this should specifically mention that the home directory must exist & be writable

end

private

def find_gemfile
Expand Down
7 changes: 7 additions & 0 deletions spec/bundler/shared_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,11 @@ module TargetNamespace
end
end
end

describe "#check_home_dir_permissions" do
it "raises a PathError" do
allow(File).to receive(:writable?).with(Dir.home).and_return(false)
Copy link
Member

Choose a reason for hiding this comment

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

please also add a test for when Dir.home does not exist

Copy link
Contributor

@JuanitoFatas JuanitoFatas Aug 26, 2016

Choose a reason for hiding this comment

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

Regarding to Dir.home, I found using user's login is more reliable:

# suppose ENV HOME is gone
> ENV.delete "HOME"

> Dir.home
ArgumentError: couldn't find HOME environment -- expanding `~'

> require "etc"; File.expand_path(Dir.home(Etc.getlogin))
> "/Users/Juan"

expect { subject.check_home_dir_permissions }.to raise_error(Bundler::PathError, /There was an error while trying to use your home path/)
end
end
end