From bece8808744ee178a4c55c6954edd30fb93b9ad3 Mon Sep 17 00:00:00 2001 From: Ry Biesemeyer Date: Thu, 2 Dec 2021 16:09:36 +0000 Subject: [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 --- lib/bundler/shared_helpers.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/bundler/shared_helpers.rb') 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 -- cgit v1.2.3