Skip to content

Update tool/ln_sr.rb #13960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ net-pop 0.1.2 https://github.com/ruby/net-pop
net-smtp 0.5.1 https://github.com/ruby/net-smtp
matrix 0.4.3 https://github.com/ruby/matrix
prime 0.1.4 https://github.com/ruby/prime
rbs 3.9.4 https://github.com/ruby/rbs
rbs 3.9.4 https://github.com/ruby/rbs f06b6f8d705ffecbac9e0b57e655a72b1e7cd077
typeprof 0.30.1 https://github.com/ruby/typeprof
debug 1.11.0 https://github.com/ruby/debug
racc 1.8.1 https://github.com/ruby/racc
Expand Down
71 changes: 35 additions & 36 deletions tool/ln_sr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,66 +29,65 @@
require 'fileutils'

include FileUtils
unless respond_to?(:ln_sr)
unless respond_to?(:ln_sr, true)
def ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil)
options = "#{force ? 'f' : ''}#{target_directory ? '' : 'T'}"
dest = File.path(dest)
srcs = Array(src)
link = proc do |s, target_dir_p = true|
s = File.path(s)
if target_dir_p
d = File.join(destdirs = dest, File.basename(s))
cmd = "ln -s#{force ? 'f' : ''}#{target_directory ? '' : 'T'}" if verbose
fu_each_src_dest0(src, dest, target_directory) do |s,d|
if target_directory
parent = File.dirname(d)
destdirs = fu_split_path(parent)
real_ddirs = fu_split_path(File.realpath(parent))
else
destdirs = File.dirname(d = dest)
destdirs ||= fu_split_path(dest)
real_ddirs ||= fu_split_path(File.realdirpath(dest))
end
destdirs = fu_split_path(File.realpath(destdirs))
if fu_starting_path?(s)
srcdirs = fu_split_path((File.realdirpath(s) rescue File.expand_path(s)))
base = fu_relative_components_from(srcdirs, destdirs)
s = File.join(*base)
srcdirs = fu_split_path(s)
i = fu_common_components(srcdirs, destdirs)
n = destdirs.size - i
n -= 1 unless target_directory
link1 = fu_clean_components(*Array.new([n, 0].max, '..'), *srcdirs[i..-1])
begin
real_sdirs = fu_split_path(File.realdirpath(s)) rescue nil
rescue
else
srcdirs = fu_clean_components(*fu_split_path(s))
base = fu_relative_components_from(fu_split_path(Dir.pwd), destdirs)
while srcdirs.first&. == ".." and base.last&.!=("..") and !fu_starting_path?(base.last)
srcdirs.shift
base.pop
end
s = File.join(*base, *srcdirs)
i = fu_common_components(real_sdirs, real_ddirs)
n = real_ddirs.size - i
n -= 1 unless target_directory
link2 = fu_clean_components(*Array.new([n, 0].max, '..'), *real_sdirs[i..-1])
link1 = link2 if link1.size > link2.size
end
fu_output_message "ln -s#{options} #{s} #{d}" if verbose
s = File.join(link1)
fu_output_message [cmd, s, d].flatten.join(' ') if verbose
next if noop
remove_file d, true if force
File.symlink s, d
end
case srcs.size
when 0
when 1
link[srcs[0], target_directory && File.directory?(dest)]
else
srcs.each(&link)
end
end

def fu_split_path(path)
def fu_split_path(path) #:nodoc:
path = File.path(path)
list = []
until (parent, base = File.split(path); parent == path or parent == ".")
list << base
if base != '..' and list.last == '..' and !(fu_have_symlink? && File.symlink?(path))
list.pop
else
list << base
end
path = parent
end
list << path
list.reverse!
end

def fu_relative_components_from(target, base) #:nodoc:
def fu_common_components(target, base) #:nodoc:
i = 0
while target[i]&.== base[i]
i += 1
end
Array.new(base.size-i, '..').concat(target[i..-1])
i
end

def fu_clean_components(*comp)
def fu_clean_components(*comp) #:nodoc:
comp.shift while comp.first == "."
return comp if comp.empty?
clean = [comp.shift]
Expand All @@ -106,11 +105,11 @@ def fu_clean_components(*comp)
end

if fu_windows?
def fu_starting_path?(path)
def fu_starting_path?(path) #:nodoc:
path&.start_with?(%r(\w:|/))
end
else
def fu_starting_path?(path)
def fu_starting_path?(path) #:nodoc:
path&.start_with?("/")
end
end
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy