summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2015-07-23 09:56:00 +0900
committerHomu <homu@barosl.com>2015-07-23 09:56:00 +0900
commit26f13d1bd365d6d3657e21ba99a9d861624649ea (patch)
treebb8037439baaaeae56ef5614a5f378ec0f53d1f4
parent8db3f4b975655da1e906c5e38fdfa15b59faf791 (diff)
parent411d6f1966f3d72e6b2d0d23df97db7d34058e88 (diff)
downloadbundler-26f13d1bd365d6d3657e21ba99a9d861624649ea.tar.gz
Auto merge of #3874 - bundler:seg-settings-permission-error, r=indirect
Raise permission error when config file isn't readable Closes #3858
-rw-r--r--lib/bundler.rb15
-rw-r--r--lib/bundler/settings.rb1
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 109cf287e6..5bb35f4d40 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -86,14 +86,21 @@ module Bundler
class MarshalError < StandardError; end
class PermissionError < BundlerError
- def initialize(file)
+ def initialize(file, permission_type = :write)
@file = file
+ @permission_type = permission_type
end
def message
- "There was an error while trying to write to `#{File.basename(@file)}`. It is likely that \n" \
- "you need to allow write permissions for the file at path: \n" \
- "#{File.expand_path(@file)}"
+ action = case @permission_type
+ when :read then "read from"
+ when :write then "write to"
+ when :executable then "execute"
+ else @permission_type.to_s
+ end
+ "There was an error while trying to #{action} `#{File.basename(@file)}`. " \
+ "It is likely that you need to grant #{@permission_type} permissions for " \
+ "the file at path: `#{File.expand_path(@file)}`."
end
status_code(23)
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 14d3f4d683..898817c963 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -229,6 +229,7 @@ module Bundler
valid_file = config_file && config_file.exist? && !config_file.size.zero?
if !ignore_config? && valid_file
config_regex = /^(BUNDLE_.+): (['"]?)(.*(?:\n(?!BUNDLE).+)?)\2$/
+ raise PermissionError.new(config_file, :read) unless config_file.readable?
config_pairs = config_file.read.scan(config_regex).map do |m|
key, _, value = m
[convert_to_backward_compatible_key(key), value.gsub(/\s+/, " ").tr('"', "'")]