Skip to content

Commit

Permalink
add_external_libs: ensure write permission on libraries
Browse files Browse the repository at this point in the history
`std::fs::copy` also copies the original file permissions.
If the original library at `lib_path` was not writable, e.g. because
it had its permission set to 0o555, the copy inherited the same
permission causing later file manipulations, like `patchelf
--set-soname` to fail.
  • Loading branch information
vlaci committed Nov 23, 2022
1 parent 12c1632 commit 7882066
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ impl BuildContext {
fs::copy(&lib_path, &dest_path)?;
libs_copied.insert(lib_path);

// fs::copy copies permissions as well, and the original
// file may have been read-only
let mut perms = fs::metadata(&dest_path)?.permissions();
perms.set_readonly(false);
fs::set_permissions(&dest_path, perms)?;

patchelf::set_soname(&dest_path, &new_soname)?;
if !lib.rpath.is_empty() || !lib.runpath.is_empty() {
patchelf::set_rpath(&dest_path, &libs_dir)?;
Expand Down

0 comments on commit 7882066

Please sign in to comment.