@@ -732,19 +732,31 @@ def ln_sf(src, dest, noop: nil, verbose: nil)
732
732
#
733
733
def ln_sr ( src , dest , target_directory : true , force : nil , noop : nil , verbose : nil )
734
734
cmd = "ln -s#{ force ? 'f' : '' } #{ target_directory ? '' : 'T' } " if verbose
735
- unless target_directory
736
- destdirs = fu_split_path ( dest )
737
- end
738
735
fu_each_src_dest0 ( src , dest , target_directory ) do |s , d |
739
736
if target_directory
740
- destdirs = fu_split_path ( File . dirname ( d ) )
741
- # else d == dest
737
+ parent = File . dirname ( d )
738
+ destdirs = fu_split_path ( parent )
739
+ real_ddirs = fu_split_path ( File . realpath ( parent ) )
740
+ else
741
+ destdirs ||= fu_split_path ( dest )
742
+ real_ddirs ||= fu_split_path ( File . realpath ( dest ) )
742
743
end
743
744
srcdirs = fu_split_path ( s )
744
745
i = fu_common_components ( srcdirs , destdirs )
745
746
n = destdirs . size - i
746
747
n -= 1 unless target_directory
747
- s = File . join ( fu_clean_components ( *Array . new ( n , '..' ) , *srcdirs [ i ..-1 ] ) )
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
752
+ else
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
758
+ end
759
+ s = File . join ( link1 )
748
760
fu_output_message [ cmd , s , d ] . flatten . join ( ' ' ) if verbose
749
761
next if noop
750
762
remove_file d , true if force
0 commit comments