Avoid to symlink under symlink
This commit is contained in:
parent
5101671cbc
commit
c093e7d645
@ -598,7 +598,7 @@ CP_R = #{config_string('CP')} -r
|
|||||||
|
|
||||||
gemlib = $(TARGET_TOPDIR)/gems/$(gem)/lib
|
gemlib = $(TARGET_TOPDIR)/gems/$(gem)/lib
|
||||||
gemlib:#{%{ $(gemlib)\n$(gemlib): $(gem_srcdir)/lib} if $nmake}
|
gemlib:#{%{ $(gemlib)\n$(gemlib): $(gem_srcdir)/lib} if $nmake}
|
||||||
$(Q) $(RUBY) $(top_srcdir)/tool/ln_sr.rb -f $(gem_srcdir)/lib $(gemlib)
|
$(Q) #{@inplace ? '$(NULLCMD) ' : ''}$(RUBY) $(top_srcdir)/tool/ln_sr.rb -f -T $(gem_srcdir)/lib $(gemlib)
|
||||||
|
|
||||||
clean-gemlib:
|
clean-gemlib:
|
||||||
$(Q) $(#{@inplace ? 'NULLCMD' : 'RM_RF'}) $(gemlib)
|
$(Q) $(#{@inplace ? 'NULLCMD' : 'RM_RF'}) $(gemlib)
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
|
|
||||||
|
target_directory = true
|
||||||
|
noop = false
|
||||||
|
force = false
|
||||||
|
|
||||||
until ARGV.empty?
|
until ARGV.empty?
|
||||||
case ARGV[0]
|
case ARGV[0]
|
||||||
when '-n'
|
when '-n'
|
||||||
noop = true
|
noop = true
|
||||||
when '-f'
|
when '-f'
|
||||||
force = true
|
force = true
|
||||||
|
when '-T'
|
||||||
|
target_directory = false
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -21,10 +27,11 @@ require 'fileutils'
|
|||||||
|
|
||||||
include FileUtils
|
include FileUtils
|
||||||
unless respond_to?(:ln_sr)
|
unless respond_to?(:ln_sr)
|
||||||
def ln_sr(src, dest, force: nil, noop: nil, verbose: nil)
|
def ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil)
|
||||||
|
options = "#{force ? 'f' : ''}#{target_directory ? '' : 'T'}"
|
||||||
dest = File.path(dest)
|
dest = File.path(dest)
|
||||||
srcs = Array.try_convert(src) || [src]
|
srcs = Array.try_convert(src) || [src]
|
||||||
link = proc do |s, target_directory = true|
|
link = proc do |s, target_dir_p = true|
|
||||||
s = File.path(s)
|
s = File.path(s)
|
||||||
if fu_starting_path?(s)
|
if fu_starting_path?(s)
|
||||||
srcdirs = fu_split_path((File.realdirpath(s) rescue File.expand_path(s)))
|
srcdirs = fu_split_path((File.realdirpath(s) rescue File.expand_path(s)))
|
||||||
@ -32,15 +39,15 @@ unless respond_to?(:ln_sr)
|
|||||||
srcdirs = fu_clean_components(*fu_split_path(s))
|
srcdirs = fu_clean_components(*fu_split_path(s))
|
||||||
end
|
end
|
||||||
destdirs = fu_split_path(File.realdirpath(dest))
|
destdirs = fu_split_path(File.realdirpath(dest))
|
||||||
destdirs.pop unless target_directory
|
destdirs.pop unless target_dir_p
|
||||||
base = fu_relative_components_from(fu_split_path(Dir.pwd), destdirs)
|
base = fu_relative_components_from(fu_split_path(Dir.pwd), destdirs)
|
||||||
while srcdirs.first&. == ".." and base.last and !fu_starting_path?(base.last)
|
while srcdirs.first&. == ".." and base.last and !fu_starting_path?(base.last)
|
||||||
srcdirs.shift
|
srcdirs.shift
|
||||||
base.pop
|
base.pop
|
||||||
end
|
end
|
||||||
s = File.join(*base, *srcdirs)
|
s = File.join(*base, *srcdirs)
|
||||||
d = target_directory ? File.join(dest, File.basename(s)) : dest
|
d = target_dir_p ? File.join(dest, File.basename(s)) : dest
|
||||||
fu_output_message "ln -s#{force ? 'f' : ''} #{s} #{d}" if verbose
|
fu_output_message "ln -s#{options} #{s} #{d}" if verbose
|
||||||
next if noop
|
next if noop
|
||||||
remove_file d, true if force
|
remove_file d, true if force
|
||||||
File.symlink s, d
|
File.symlink s, d
|
||||||
@ -48,7 +55,7 @@ unless respond_to?(:ln_sr)
|
|||||||
case srcs.size
|
case srcs.size
|
||||||
when 0
|
when 0
|
||||||
when 1
|
when 1
|
||||||
link[srcs[0], File.directory?(dest)]
|
link[srcs[0], target_directory && File.directory?(dest)]
|
||||||
else
|
else
|
||||||
srcs.each(&link)
|
srcs.each(&link)
|
||||||
end
|
end
|
||||||
@ -103,7 +110,7 @@ end
|
|||||||
|
|
||||||
if File.respond_to?(:symlink)
|
if File.respond_to?(:symlink)
|
||||||
begin
|
begin
|
||||||
ln_sr(src, dest, verbose: true, force: force, noop: noop)
|
ln_sr(src, dest, verbose: true, target_directory: target_directory, force: force, noop: noop)
|
||||||
rescue NotImplementedError, Errno::EPERM
|
rescue NotImplementedError, Errno::EPERM
|
||||||
else
|
else
|
||||||
exit
|
exit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user