From 754f0ea818d65dc9cc817a67aed16e8b5ee3739a Mon Sep 17 00:00:00 2001 From: Zach Hanson Date: Mon, 24 Jun 2024 00:55:32 -0700 Subject: [PATCH] Adds check for existing libc.so.6 This commit adds a check to see if libc.so.6 already exists in the target directory. If it does it displays a notice but continues. --- src/patch_bin.rs | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/patch_bin.rs b/src/patch_bin.rs index fc4e95d..cc0fc13 100644 --- a/src/patch_bin.rs +++ b/src/patch_bin.rs @@ -85,24 +85,36 @@ fn run_patchelf_option(bin: &Path, option: &str, argument: &PathBuf) -> Result<( /// /// If `libc` doesn't have the filename `libc.so.6`, /// make a symlink with file name `libc.so.6` in the same directory as `libc`, -/// and make it point to `libc`. +/// and make it point to `libc`. If it already exists, do nothing. fn symlink_libc(libc: &Path) -> Result<()> { let libc_file_name = libc.file_name().context(FileNameSnafu { path: libc })?; if libc_file_name != LIBC_FILE_NAME { let link = libc.with_file_name(LIBC_FILE_NAME); - println!( - "{}", - format!( - "symlinking {} -> {}", - link.to_string_lossy().bold(), - libc_file_name.to_string_lossy().bold() - ) - .green() - ); - std::os::unix::fs::symlink(libc_file_name, &link).context(SymlinkSnafu { - link, - target: libc_file_name, - })?; + + if link.exists() { + println!( + "{}", + format!( + "{} already exists, not creating symlink", + link.to_string_lossy().bold(), + ) + .yellow() + ); + } else { + println!( + "{}", + format!( + "symlinking {} -> {}", + link.to_string_lossy().bold(), + libc_file_name.to_string_lossy().bold() + ) + .green() + ); + std::os::unix::fs::symlink(libc_file_name, &link).context(SymlinkSnafu { + link, + target: libc_file_name, + })?; + } } Ok(()) }