Method: Bundler::SharedHelpers#filesystem_access

Defined in:
lib/bundler/shared_helpers.rb

#filesystem_access(path, action = :write) { ... } ⇒ Object

Rescues permissions errors raised by file system operations (ie. Errno:EACCESS, Errno::EAGAIN) and raises more friendly errors instead.

Examples:

filesystem_access("vendor/cache", :create) do
  FileUtils.mkdir_p("vendor/cache")
end

Parameters:

  • path (String)

    the path that the action will be attempted to

  • action (Symbol, #to_s) (defaults to: :write)

    the type of operation that will be performed. For example: :write, :read, :exec

Yields:

  • path

Raises:

See Also:

  • Bundler::SharedHelpers.{Bundler{Bundler::PermissionError}
[View source]

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bundler/shared_helpers.rb', line 104

def filesystem_access(path, action = :write, &block)
  yield(path.dup)
rescue Errno::EACCES => e
  raise unless e.message.include?(path.to_s) || action == :create

  raise PermissionError.new(path, action)
rescue Errno::EAGAIN
  raise TemporaryResourceError.new(path, action)
rescue Errno::EPROTO
  raise VirtualProtocolError.new
rescue Errno::ENOSPC
  raise NoSpaceOnDeviceError.new(path, action)
rescue Errno::ENOTSUP
  raise OperationNotSupportedError.new(path, action)
rescue Errno::EPERM
  raise OperationNotPermittedError.new(path, action)
rescue Errno::EROFS
  raise ReadOnlyFileSystemError.new(path, action)
rescue Errno::EEXIST, Errno::ENOENT
  raise
rescue SystemCallError => e
  raise GenericSystemCallError.new(e, "There was an error #{[:create, :write].include?(action) ? "creating" : "accessing"} `#{path}`.")
end