181181#
182182module Bundler ::FileUtils
183183 # The version number.
184- VERSION = "1.7.3 "
184+ VERSION = "1.8.0 "
185185
186186 def self . private_module_function ( name ) #:nodoc:
187187 module_function name
@@ -706,11 +706,12 @@ def cp_lr(src, dest, noop: nil, verbose: nil,
706706 #
707707 def ln_s ( src , dest , force : nil , relative : false , target_directory : true , noop : nil , verbose : nil )
708708 if relative
709- return ln_sr ( src , dest , force : force , noop : noop , verbose : verbose )
709+ return ln_sr ( src , dest , force : force , target_directory : target_directory , noop : noop , verbose : verbose )
710710 end
711- fu_output_message "ln -s#{ force ? 'f' : '' } #{ [ src , dest ] . flatten . join ' ' } " if verbose
711+ fu_output_message "ln -s#{ force ? 'f' : '' } #{
712+ target_directory ? '' : 'T' } #{ [ src , dest ] . flatten . join ' ' } " if verbose
712713 return if noop
713- fu_each_src_dest0 ( src , dest ) do |s , d |
714+ fu_each_src_dest0 ( src , dest , target_directory ) do |s , d |
714715 remove_file d , true if force
715716 File . symlink s , d
716717 end
@@ -730,42 +731,37 @@ def ln_sf(src, dest, noop: nil, verbose: nil)
730731 # Like Bundler::FileUtils.ln_s, but create links relative to +dest+.
731732 #
732733 def ln_sr ( src , dest , target_directory : true , force : nil , noop : nil , verbose : nil )
733- options = "#{ force ? 'f' : '' } #{ target_directory ? '' : 'T' } "
734- dest = File . path ( dest )
735- srcs = Array ( src )
736- link = proc do |s , target_dir_p = true |
737- s = File . path ( s )
738- if target_dir_p
739- d = File . join ( destdirs = dest , File . basename ( s ) )
734+ cmd = "ln -s#{ force ? 'f' : '' } #{ target_directory ? '' : 'T' } " if verbose
735+ fu_each_src_dest0 ( src , dest , target_directory ) do |s , d |
736+ if target_directory
737+ parent = File . dirname ( d )
738+ destdirs = fu_split_path ( parent )
739+ real_ddirs = fu_split_path ( File . realpath ( parent ) )
740740 else
741- destdirs = File . dirname ( d = dest )
741+ destdirs ||= fu_split_path ( dest )
742+ real_ddirs ||= fu_split_path ( File . realdirpath ( dest ) )
742743 end
743- destdirs = fu_split_path ( File . realpath ( destdirs ) )
744- if fu_starting_path? ( s )
745- srcdirs = fu_split_path ( ( File . realdirpath ( s ) rescue File . expand_path ( s ) ) )
746- base = fu_relative_components_from ( srcdirs , destdirs )
747- s = File . join ( *base )
744+ srcdirs = fu_split_path ( s )
745+ i = fu_common_components ( srcdirs , destdirs )
746+ n = destdirs . size - i
747+ n -= 1 unless target_directory
748+ link1 = fu_clean_components ( *Array . new ( [ n , 0 ] . max , '..' ) , *srcdirs [ i ..-1 ] )
749+ begin
750+ real_sdirs = fu_split_path ( File . realdirpath ( s ) ) rescue nil
751+ rescue
748752 else
749- srcdirs = fu_clean_components ( *fu_split_path ( s ) )
750- base = fu_relative_components_from ( fu_split_path ( Dir . pwd ) , destdirs )
751- while srcdirs . first &. == ".." and base . last &.!=( ".." ) and !fu_starting_path? ( base . last )
752- srcdirs . shift
753- base . pop
754- end
755- s = File . join ( *base , *srcdirs )
753+ i = fu_common_components ( real_sdirs , real_ddirs )
754+ n = real_ddirs . size - i
755+ n -= 1 unless target_directory
756+ link2 = fu_clean_components ( *Array . new ( [ n , 0 ] . max , '..' ) , *real_sdirs [ i ..-1 ] )
757+ link1 = link2 if link1 . size > link2 . size
756758 end
757- fu_output_message "ln -s#{ options } #{ s } #{ d } " if verbose
759+ s = File . join ( link1 )
760+ fu_output_message [ cmd , s , d ] . flatten . join ( ' ' ) if verbose
758761 next if noop
759762 remove_file d , true if force
760763 File . symlink s , d
761764 end
762- case srcs . size
763- when 0
764- when 1
765- link [ srcs [ 0 ] , target_directory && File . directory? ( dest ) ]
766- else
767- srcs . each ( &link )
768- end
769765 end
770766 module_function :ln_sr
771767
@@ -800,13 +796,13 @@ def ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil
800796 # File.file?('dest1/dir1/t2.txt') # => true
801797 # File.file?('dest1/dir1/t3.txt') # => true
802798 #
803- # Keyword arguments:
799+ # Optional arguments:
804800 #
805- # - <tt> dereference_root: true</tt> - dereferences +src+ if it is a symbolic link.
806- # - <tt> remove_destination: true</tt> - removes +dest+ before creating links.
801+ # - + dereference_root+ - dereferences +src+ if it is a symbolic link (+false+ by default) .
802+ # - + remove_destination+ - removes +dest+ before creating links (+false+ by default) .
807803 #
808804 # Raises an exception if +dest+ is the path to an existing file or directory
809- # and keyword argument <tt> remove_destination: true</tt> is not given.
805+ # and optional argument + remove_destination+ is not given.
810806 #
811807 # Related: Bundler::FileUtils.ln (has different options).
812808 #
@@ -1029,12 +1025,12 @@ def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
10291025 # directories, and symbolic links;
10301026 # other file types (FIFO streams, device files, etc.) are not supported.
10311027 #
1032- # Keyword arguments:
1028+ # Optional arguments:
10331029 #
1034- # - <tt> dereference_root: true</tt> - if +src+ is a symbolic link,
1035- # follows the link.
1036- # - <tt> preserve: true</tt> - preserves file times.
1037- # - <tt> remove_destination: true</tt> - removes +dest+ before copying files.
1030+ # - + dereference_root+ - if +src+ is a symbolic link,
1031+ # follows the link (+false+ by default) .
1032+ # - + preserve+ - preserves file times (+false+ by default) .
1033+ # - + remove_destination+ - removes +dest+ before copying files (+false+ by default) .
10381034 #
10391035 # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
10401036 #
@@ -1065,12 +1061,12 @@ def copy_entry(src, dest, preserve = false, dereference_root = false, remove_des
10651061 # Bundler::FileUtils.copy_file('src0.txt', 'dest0.txt')
10661062 # File.file?('dest0.txt') # => true
10671063 #
1068- # Keyword arguments:
1064+ # Optional arguments:
10691065 #
1070- # - <tt> dereference: false</tt> - if +src+ is a symbolic link,
1071- # does not follow the link.
1072- # - <tt> preserve: true</tt> - preserves file times.
1073- # - <tt> remove_destination: true</tt> - removes +dest+ before copying files.
1066+ # - + dereference+ - if +src+ is a symbolic link,
1067+ # follows the link (+true+ by default) .
1068+ # - + preserve+ - preserves file times (+false+ by default) .
1069+ # - + remove_destination+ - removes +dest+ before copying files (+false+ by default) .
10741070 #
10751071 # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
10761072 #
@@ -1491,7 +1487,8 @@ def remove_file(path, force = false)
14911487 # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
14921488 #
14931489 def remove_dir ( path , force = false )
1494- remove_entry path , force # FIXME?? check if it is a directory
1490+ raise Errno ::ENOTDIR , path unless force or File . directory? ( path )
1491+ remove_entry path , force
14951492 end
14961493 module_function :remove_dir
14971494
@@ -2475,6 +2472,10 @@ def fu_each_src_dest(src, dest) #:nodoc:
24752472
24762473 def fu_each_src_dest0 ( src , dest , target_directory = true ) #:nodoc:
24772474 if tmp = Array . try_convert ( src )
2475+ unless target_directory or tmp . size <= 1
2476+ tmp = tmp . map { |f | File . path ( f ) } # A workaround for RBS
2477+ raise ArgumentError , "extra target #{ tmp } "
2478+ end
24782479 tmp . each do |s |
24792480 s = File . path ( s )
24802481 yield s , ( target_directory ? File . join ( dest , File . basename ( s ) ) : dest )
@@ -2509,22 +2510,26 @@ def fu_split_path(path) #:nodoc:
25092510 path = File . path ( path )
25102511 list = [ ]
25112512 until ( parent , base = File . split ( path ) ; parent == path or parent == "." )
2512- list << base
2513+ if base != '..' and list . last == '..' and !( fu_have_symlink? && File . symlink? ( path ) )
2514+ list . pop
2515+ else
2516+ list << base
2517+ end
25132518 path = parent
25142519 end
25152520 list << path
25162521 list . reverse!
25172522 end
25182523 private_module_function :fu_split_path
25192524
2520- def fu_relative_components_from ( target , base ) #:nodoc:
2525+ def fu_common_components ( target , base ) #:nodoc:
25212526 i = 0
25222527 while target [ i ] &.== base [ i ]
25232528 i += 1
25242529 end
2525- Array . new ( base . size - i , '..' ) . concat ( target [ i ..- 1 ] )
2530+ i
25262531 end
2527- private_module_function :fu_relative_components_from
2532+ private_module_function :fu_common_components
25282533
25292534 def fu_clean_components ( *comp ) #:nodoc:
25302535 comp . shift while comp . first == "."
@@ -2534,7 +2539,7 @@ def fu_clean_components(*comp) #:nodoc:
25342539 while c = comp . shift
25352540 if c == ".." and clean . last != ".." and !( fu_have_symlink? && File . symlink? ( path ) )
25362541 clean . pop
2537- path . chomp !( %r((?<=\A |/)[^/]+/\z ) , "" )
2542+ path . sub !( %r((?<=\A |/)[^/]+/\z ) , "" )
25382543 else
25392544 clean << c
25402545 path << c << "/"
0 commit comments