@@ -176,33 +176,37 @@ pub async fn mangle_package_symlinks(
176176
177177 let provides = provides. unwrap_or_default ( ) ;
178178 for provide in provides {
179- if let Some ( ref target ) = provide. target {
180- let real_path = install_dir . join ( provide. name . clone ( ) ) ;
179+ let real_path = install_dir . join ( provide. name . clone ( ) ) ;
180+ let target_name = if let Some ( ref target ) = provide. target {
181181 let is_symlink = matches ! (
182182 provide. strategy,
183183 Some ( ProvideStrategy :: KeepTargetOnly ) | Some ( ProvideStrategy :: KeepBoth )
184184 ) ;
185185 if is_symlink {
186- let target_name = bin_dir. join ( target) ;
187- if target_name. is_symlink ( ) || target_name. is_file ( ) {
188- std:: fs:: remove_file ( & target_name)
189- . with_context ( || format ! ( "removing provide {}" , target_name. display( ) ) ) ?;
190- }
191- unix:: fs:: symlink ( & real_path, & target_name) . with_context ( || {
192- format ! (
193- "creating symlink {} -> {}" ,
194- real_path. display( ) ,
195- target_name. display( )
196- )
197- } ) ?;
198-
199- symlinks. push ( ( real_path, target_name) ) ;
186+ bin_dir. join ( target)
187+ } else {
188+ continue ;
200189 }
190+ } else {
191+ bin_dir. join ( provide. name . clone ( ) )
192+ } ;
193+
194+ if target_name. is_symlink ( ) || target_name. is_file ( ) {
195+ std:: fs:: remove_file ( & target_name)
196+ . with_context ( || format ! ( "removing provide {}" , target_name. display( ) ) ) ?;
201197 }
198+ unix:: fs:: symlink ( & real_path, & target_name) . with_context ( || {
199+ format ! (
200+ "creating symlink {} -> {}" ,
201+ real_path. display( ) ,
202+ target_name. display( )
203+ )
204+ } ) ?;
205+ symlinks. push ( ( real_path, target_name) ) ;
202206 }
203207
204208 if provides. is_empty ( ) {
205- for entry in fs:: read_dir ( & install_dir) . with_context ( || {
209+ for entry in fs:: read_dir ( install_dir) . with_context ( || {
206210 format ! (
207211 "reading install directory {} for ELF detection" ,
208212 install_dir. display( )
@@ -216,27 +220,25 @@ pub async fn mangle_package_symlinks(
216220 )
217221 } ) ?
218222 . path ( ) ;
219- if path. is_file ( ) {
220- if is_elf ( & path) . await {
221- if let Some ( file_name) = path. file_name ( ) {
222- let symlink_target_path = bin_dir. join ( file_name) ;
223- if symlink_target_path. is_symlink ( ) || symlink_target_path. is_file ( ) {
224- std:: fs:: remove_file ( & symlink_target_path) . with_context ( || {
225- format ! (
226- "removing existing file/symlink at {}" ,
227- symlink_target_path. display( )
228- )
229- } ) ?;
230- }
231- unix:: fs:: symlink ( & path, & symlink_target_path) . with_context ( || {
223+ if path. is_file ( ) && is_elf ( & path) . await {
224+ if let Some ( file_name) = path. file_name ( ) {
225+ let symlink_target_path = bin_dir. join ( file_name) ;
226+ if symlink_target_path. is_symlink ( ) || symlink_target_path. is_file ( ) {
227+ std:: fs:: remove_file ( & symlink_target_path) . with_context ( || {
232228 format ! (
233- "creating ELF symlink {} -> {}" ,
234- path. display( ) ,
229+ "removing existing file/symlink at {}" ,
235230 symlink_target_path. display( )
236231 )
237232 } ) ?;
238- symlinks. push ( ( path. clone ( ) , symlink_target_path. clone ( ) ) ) ;
239233 }
234+ unix:: fs:: symlink ( & path, & symlink_target_path) . with_context ( || {
235+ format ! (
236+ "creating ELF symlink {} -> {}" ,
237+ path. display( ) ,
238+ symlink_target_path. display( )
239+ )
240+ } ) ?;
241+ symlinks. push ( ( path. clone ( ) , symlink_target_path. clone ( ) ) ) ;
240242 }
241243 }
242244 }
0 commit comments