@@ -741,14 +741,10 @@ def ln_sr(src, dest, force: nil, noop: nil, verbose: nil)
741
741
srcs = Array . try_convert ( src ) || [ src ]
742
742
link = proc do |s , target_directory = true |
743
743
s = File . path ( s )
744
- srcdirs = ( File . realdirpath ( s ) rescue File . expand_path ( s ) ) . split ( File :: SEPARATOR )
745
- destdirs = File . realdirpath ( dest ) . split ( File :: SEPARATOR )
744
+ srcdirs = fu_split_path ( ( File . realdirpath ( s ) rescue File . expand_path ( s ) ) )
745
+ destdirs = fu_split_path ( File . realdirpath ( dest ) )
746
746
destdirs . pop unless target_directory
747
- while srcdirs . first &.== destdirs . first
748
- srcdirs . shift
749
- destdirs . shift
750
- end
751
- s = File . join ( Array . new ( destdirs . size , '..' ) , srcdirs )
747
+ s = File . join ( fu_relative_components_from ( srcdirs , destdirs ) )
752
748
d = target_directory ? File . join ( dest , File . basename ( s ) ) : dest
753
749
fu_output_message "ln -s#{ force ? 'f' : '' } #{ s } #{ d } " if verbose
754
750
remove_file d , true if force
@@ -2495,6 +2491,20 @@ def fu_output_message(msg) #:nodoc:
2495
2491
end
2496
2492
private_module_function :fu_output_message
2497
2493
2494
+ def fu_split_path ( path )
2495
+ File . path ( path ) . split ( File ::SEPARATOR )
2496
+ end
2497
+ private_module_function :fu_split_path
2498
+
2499
+ def fu_relative_components_from ( target , base ) #:nodoc:
2500
+ i = 0
2501
+ while target [ i ] &.== base [ i ]
2502
+ i += 1
2503
+ end
2504
+ Array . new ( base . size -i , '..' ) . concat ( target [ i ..-1 ] )
2505
+ end
2506
+ private_module_function :fu_relative_components_from
2507
+
2498
2508
# This hash table holds command options.
2499
2509
OPT_TABLE = { } #:nodoc: internal use only
2500
2510
( private_instance_methods & methods ( false ) ) . inject ( OPT_TABLE ) { |tbl , name |
0 commit comments