Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix permissions of add_lib, when copying readonly libraries (e.g. of nix/store) to avoid a Permissions Denied Error #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ndk-build/src/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::collections::HashMap;
use std::collections::HashSet;
use std::ffi::OsStr;
use std::fs;
#[cfg(target_family = "unix")]
use std::os::unix::prelude::PermissionsExt;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -66,7 +68,7 @@ impl ApkConfig {
}

pub fn create_apk(&self) -> Result<UnalignedApk, NdkError> {
std::fs::create_dir_all(&self.build_dir)?;
fs::create_dir_all(&self.build_dir)?;
self.manifest.write_to(&self.build_dir)?;

let target_sdk_version = self
Expand Down Expand Up @@ -124,11 +126,13 @@ impl<'a> UnalignedApk<'a> {
let abi = target.android_abi();
let lib_path = Path::new("lib").join(abi).join(path.file_name().unwrap());
let out = self.config.build_dir.join(&lib_path);
std::fs::create_dir_all(out.parent().unwrap())?;
fs::create_dir_all(out.parent().unwrap())?;

match self.config.strip {
StripConfig::Default => {
std::fs::copy(path, out)?;
fs::copy(path, out.clone())?;
#[cfg(target_family = "unix")]
fs::set_permissions(out, fs::Permissions::from_mode(0o644))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should at the very least have a comment documenting this workaround for Nix 😉

}
StripConfig::Strip | StripConfig::Split => {
let obj_copy = self.config.ndk.toolchain_bin("objcopy", target)?;
Expand Down