summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgis Anastasopoulos <agis.anast@gmail.com>2015-09-26 16:08:59 +0300
committerAgis Anastasopoulos <agis.anast@gmail.com>2015-09-27 16:53:48 +0300
commit643a57c91a0d1e33ebc37bd8656f9e8d5a3749a6 (patch)
treeb9667fa61ffc54589866d294c6f79a61bca93dc7
parent302b4cef21f8e8d97bfb218cc550a7862875babd (diff)
downloadbundler-643a57c91a0d1e33ebc37bd8656f9e8d5a3749a6.tar.gz
Introduce SharedHelpers#filesystem_access
-rw-r--r--lib/bundler/shared_helpers.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 1f6c49106e..19e75186dd 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -92,6 +92,30 @@ module Bundler
ENV["RUBYLIB"] = rubylib.uniq.join(File::PATH_SEPARATOR)
end
+ # Rescues permissions errors raised by file system operations
+ # (ie. Errno:EACCESS) and raises more friendly errors instead.
+ #
+ # @param path [String] the path that the action will be attempted to
+ # @param action [Symbol, #to_s] the type of operation that will be
+ # performed. For example: :write, :read, :exec
+ #
+ # @yield path
+ #
+ # @raise [Bundler::PermissionError] if Errno:EACCES is raised in the
+ # given block
+ #
+ # @example
+ # filesystem_access("vendor/cache", :write) do
+ # FileUtils.mkdir_p("vendor/cache")
+ # end
+ #
+ # @see {Bundler::PermissionError}
+ def filesystem_access(path, action = :write)
+ yield path
+ rescue Errno::EACCES
+ raise PermissionError.new(path, action)
+ end
+
private
def find_gemfile