aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2022-07-12 12:33:12 +0200
committergit <svn-admin@ruby-lang.org>2022-07-14 15:06:09 +0900
commit76de7a92b90e216c6645e93a3a034bc2f4257b03 (patch)
treeaa663dc015e51cdab1ef3cfae6f57648b5c11cb5 /lib
parent9d900620cafc379f527ee04a338f3a7f5daf6962 (diff)
downloadruby-76de7a92b90e216c6645e93a3a034bc2f4257b03.tar.gz
[rubygems/rubygems] Fix misleading error if compact index cannot be copied
Previously if `~/.bundle/cache/compact_index/rubygems.org.*/version` were owned by root with read-only access, `bundle install` would fail with a misleading error message. For example: ``` There was an error while trying to write to `/tmp/bundler-compact-index-20220711-1823-npllre/versions`. It is likely that you need to grant write permissions for that path. ``` This happened because the EACCESS error was caught by `SharedHelpers.filesystem_access`, which makes it look like the target directory is at fault instead of the source. We can't simply drop this guard because that causes the opposite problem: the permission error appears to come from the source instead of the target, since `CompactIndexClient::Cache#lines` also wraps read access errors. Instead, bring a minimal implementation of `FileUtils.cp` and nest calls to `SharedHelpers.filesystem_access` properly. https://github.com/rubygems/rubygems/commit/320822c070 Co-authored-by: Stan Hu <stanhu@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/compact_index_client/updater.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb
index d9b9cec0d4..5b430dfbe2 100644
--- a/lib/bundler/compact_index_client/updater.rb
+++ b/lib/bundler/compact_index_client/updater.rb
@@ -31,9 +31,8 @@ module Bundler
# first try to fetch any new bytes on the existing file
if retrying.nil? && local_path.file?
- SharedHelpers.filesystem_access(local_temp_path) do
- FileUtils.cp local_path, local_temp_path
- end
+ copy_file local_path, local_temp_path
+
headers["If-None-Match"] = etag_for(local_temp_path)
headers["Range"] =
if local_temp_path.size.nonzero?
@@ -98,6 +97,20 @@ module Bundler
SharedHelpers.digest(:MD5).hexdigest(File.read(path))
end
end
+
+ private
+
+ def copy_file(source, dest)
+ SharedHelpers.filesystem_access(source, :read) do
+ File.open(source, "r") do |s|
+ SharedHelpers.filesystem_access(dest, :write) do
+ File.open(dest, "wb", s.stat.mode) do |f|
+ IO.copy_stream(s, f)
+ end
+ end
+ end
+ end
+ end
end
end
end