aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/shared_helpers.rb
diff options
context:
space:
mode:
authorRy Biesemeyer <ry.biesemeyer@elastic.co>2021-12-02 16:09:36 +0000
committergit <svn-admin@ruby-lang.org>2023-09-27 05:20:58 +0000
commitbece8808744ee178a4c55c6954edd30fb93b9ad3 (patch)
tree32cc1edd33a6f08a7ffb27a1559a5348e022359f /lib/bundler/shared_helpers.rb
parenta812f1fed0e6e184447ca00b713d54b25be05911 (diff)
downloadruby-bece8808744ee178a4c55c6954edd30fb93b9ad3.tar.gz
[rubygems/rubygems] Centralize logic using `Pathname#relative_path_from`
To avoid potential crashes when trying to jump from a drive to another on Windows, and take the change refactor things a bit. https://github.com/rubygems/rubygems/commit/7c9a9a431a
Diffstat (limited to 'lib/bundler/shared_helpers.rb')
-rw-r--r--lib/bundler/shared_helpers.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index d1d4e1d07a..165982ad0a 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -197,6 +197,21 @@ module Bundler
filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } }
end
+ def relative_gemfile_path
+ relative_path_to(Bundler.default_gemfile)
+ end
+
+ def relative_lockfile_path
+ relative_path_to(Bundler.default_lockfile)
+ end
+
+ def relative_path_to(destination, from: pwd)
+ Pathname.new(destination).relative_path_from(from).to_s
+ rescue ArgumentError
+ # on Windows, if source and destination are on different drivers, there's no relative path from one to the other
+ destination
+ end
+
private
def validate_bundle_path