summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgis Anastasopoulos <agis.anast@gmail.com>2015-09-26 16:09:36 +0300
committerAgis Anastasopoulos <agis.anast@gmail.com>2015-09-27 16:54:11 +0300
commite6e1ff5953e5713fbdd7c2664ed785b426bea827 (patch)
treec550268658546d5f4a604abe242f00587f990e04
parent643a57c91a0d1e33ebc37bd8656f9e8d5a3749a6 (diff)
downloadbundler-e6e1ff5953e5713fbdd7c2664ed785b426bea827.tar.gz
Wrap filesystem operations with #filesystem_access
-rw-r--r--lib/bundler.rb6
-rw-r--r--lib/bundler/definition.rb6
-rw-r--r--lib/bundler/gem_helper.rb2
-rw-r--r--lib/bundler/installer.rb8
-rw-r--r--lib/bundler/runtime.rb8
-rw-r--r--lib/bundler/settings.rb10
-rw-r--r--lib/bundler/source/git/git_proxy.rb12
-rw-r--r--lib/bundler/source/path/installer.rb4
-rw-r--r--lib/bundler/source/rubygems.rb16
9 files changed, 49 insertions, 23 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 3708821f6e..db52b006ce 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -146,7 +146,7 @@ module Bundler
@bin_path ||= begin
path = settings[:bin] || "bin"
path = Pathname.new(path).expand_path(root).expand_path
- FileUtils.mkdir_p(path)
+ SharedHelpers.filesystem_access(path) {|p| FileUtils.mkdir_p(p) }
path
end
end
@@ -349,7 +349,9 @@ module Bundler
if requires_sudo?
sudo "mkdir -p '#{path}'" unless File.exist?(path)
else
- FileUtils.mkdir_p(path)
+ SharedHelpers.filesystem_access(path, :write) do |p|
+ FileUtils.mkdir_p(p)
+ end
end
end
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index a6e124eddb..d1849e484a 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -265,9 +265,9 @@ module Bundler
return
end
- File.open(file, "wb") {|f| f.puts(contents) }
- rescue Errno::EACCES
- raise PermissionError.new(file)
+ SharedHelpers.filesystem_access(file) do |p|
+ File.open(p, "wb") {|f| f.puts(contents) }
+ end
end
# Returns the version of Bundler that is creating or has created
diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb
index ba1323356a..88e61c5af2 100644
--- a/lib/bundler/gem_helper.rb
+++ b/lib/bundler/gem_helper.rb
@@ -74,7 +74,7 @@ module Bundler
file_name = nil
sh("gem build -V '#{spec_path}'") {
file_name = File.basename(built_gem_path)
- FileUtils.mkdir_p(File.join(base, "pkg"))
+ SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) }
FileUtils.mv(built_gem_path, "pkg")
Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}."
}
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 00bd2158eb..29f2a30fb0 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -215,7 +215,9 @@ module Bundler
def generate_standalone(groups)
standalone_path = Bundler.settings[:path]
bundler_path = File.join(standalone_path, "bundler")
- FileUtils.mkdir_p(bundler_path)
+ SharedHelpers.filesystem_access(bundler_path) do |p|
+ FileUtils.mkdir_p(p)
+ end
paths = []
@@ -262,7 +264,9 @@ module Bundler
end
def create_bundle_path
- Bundler.mkdir_p(Bundler.bundle_path.to_s) unless Bundler.bundle_path.exist?
+ SharedHelpers.filesystem_access(Bundler.bundle_path.to_s) do |p|
+ Bundler.mkdir_p(p)
+ end unless Bundler.bundle_path.exist?
rescue Errno::EEXIST
raise PathError, "Could not install to path `#{Bundler.settings[:path]}` " \
"because of an invalid symlink. Remove the symlink so the directory can be created."
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index d0b81d6624..b214ebc988 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -110,7 +110,9 @@ module Bundler
def cache(custom_path = nil)
cache_path = Bundler.app_cache(custom_path)
- FileUtils.mkdir_p(cache_path) unless File.exist?(cache_path)
+ SharedHelpers.filesystem_access(cache_path) do |p|
+ FileUtils.mkdir_p(p)
+ end unless File.exist?(cache_path)
Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}"
specs.each do |spec|
@@ -128,7 +130,9 @@ module Bundler
end
def prune_cache(cache_path)
- FileUtils.mkdir_p(cache_path) unless File.exist?(cache_path)
+ SharedHelpers.filesystem_access(cache_path) do |p|
+ FileUtils.mkdir_p(p)
+ end unless File.exist?(cache_path)
resolve = @definition.resolve
prune_gem_cache(resolve, cache_path)
prune_git_and_path_cache(resolve, cache_path)
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index bf465f8eec..1bea85f369 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -208,14 +208,14 @@ module Bundler
unless hash[key] == value
hash[key] = value
hash.delete(key) if value.nil?
- FileUtils.mkdir_p(file.dirname)
- require "bundler/psyched_yaml"
- File.open(file, "w") {|f| f.puts YAML.dump(hash) }
+ SharedHelpers.filesystem_access(file) do |p|
+ FileUtils.mkdir_p(p.dirname)
+ require "bundler/psyched_yaml"
+ File.open(p, "w") {|f| f.puts YAML.dump(hash) }
+ end
end
value
- rescue Errno::EACCES
- raise PermissionError.new(file)
end
def global_config_file
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb
index 739f4e09a1..40e3d205ae 100644
--- a/lib/bundler/source/git/git_proxy.rb
+++ b/lib/bundler/source/git/git_proxy.rb
@@ -76,7 +76,9 @@ module Bundler
end
else
Bundler.ui.info "Fetching #{uri}"
- FileUtils.mkdir_p(path.dirname)
+ SharedHelpers.filesystem_access(path.dirname) do |p|
+ FileUtils.mkdir_p(p)
+ end
git_retry %|clone #{uri_escaped_with_configured_credentials} "#{path}" --bare --no-hardlinks --quiet|
end
end
@@ -85,8 +87,12 @@ module Bundler
# method 1
unless File.exist?(destination.join(".git"))
begin
- FileUtils.mkdir_p(destination.dirname)
- FileUtils.rm_rf(destination)
+ SharedHelpers.filesystem_access(destination.dirname) do |p|
+ FileUtils.mkdir_p(p)
+ end
+ SharedHelpers.filesystem_access(destination) do |p|
+ FileUtils.rm_rf(p)
+ end
git_retry %|clone --no-checkout --quiet "#{path}" "#{destination}"|
File.chmod(((File.stat(destination).mode | 0777) & ~File.umask), destination)
rescue Errno::EEXIST => e
diff --git a/lib/bundler/source/path/installer.rb b/lib/bundler/source/path/installer.rb
index a4a2461ed8..87e9a6e9ca 100644
--- a/lib/bundler/source/path/installer.rb
+++ b/lib/bundler/source/path/installer.rb
@@ -27,7 +27,9 @@ module Bundler
super
if Bundler.requires_sudo?
- Bundler.mkdir_p @gem_bin_dir
+ SharedHelpers.filesystem_access(@gem_bin_dir) do |p|
+ Bundler.mkdir_p(p)
+ end
spec.executables.each do |exe|
Bundler.sudo "cp -R #{@bin_dir}/#{exe} #{@gem_bin_dir}"
end
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index f59778737b..b91f32acd2 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -153,12 +153,16 @@ module Bundler
ext_src.gsub!(src[0..-6], "")
dst = File.dirname(File.join(dst, ext_src))
end
- Bundler.mkdir_p dst
+ SharedHelpers.filesystem_access(dst) do |p|
+ Bundler.mkdir_p(p)
+ end
Bundler.sudo "cp -R #{src} #{dst}" if Dir[src].any?
end
spec.executables.each do |exe|
- Bundler.mkdir_p Bundler.system_bindir
+ SharedHelpers.filesystem_access(Bundler.system_bindir) do |p|
+ Bundler.mkdir_p(p)
+ end
Bundler.sudo "cp -R #{install_path}/bin/#{exe} #{Bundler.system_bindir}/"
end
end
@@ -399,11 +403,15 @@ module Bundler
download_path = Bundler.requires_sudo? ? Bundler.tmp(spec.full_name) : Bundler.rubygems.gem_dir
gem_path = "#{Bundler.rubygems.gem_dir}/cache/#{spec.full_name}.gem"
- FileUtils.mkdir_p("#{download_path}/cache")
+ SharedHelpers.filesystem_access("#{download_path}/cache") do |p|
+ FileUtils.mkdir_p(p)
+ end
Bundler.rubygems.download_gem(spec, uri, download_path)
if Bundler.requires_sudo?
- Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/cache"
+ SharedHelpers.filesystem_access("#{Bundler.rubygems.gem_dir}/cache") do |p|
+ Bundler.mkdir_p(p)
+ end
Bundler.sudo "mv #{download_path}/cache/#{spec.full_name}.gem #{gem_path}"
end