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

Keep file mode on Unix #1622

Merged
merged 1 commit into from
May 20, 2023
Merged
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
26 changes: 20 additions & 6 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use std::collections::{HashMap, HashSet};
use std::env;
use std::ffi::OsStr;
use std::fmt::Write as _;
#[cfg(target_family = "unix")]
#[cfg(unix)]
use std::fs::OpenOptions;
use std::io;
use std::io::{Read, Write};
#[cfg(target_family = "unix")]
use std::os::unix::fs::OpenOptionsExt;
#[cfg(unix)]
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::str;
Expand Down Expand Up @@ -1160,7 +1160,12 @@ pub fn write_python_part(
if source.is_dir() {
writer.add_directory(target)?;
} else {
writer.add_file(target, source)?;
let permissions = source.metadata()?.permissions();
#[cfg(unix)]
let mode = permissions.mode();
#[cfg(not(unix))]
let mode = 0o644;
writer.add_file_with_permissions(target, source, mode)?;
}
}
}
Expand Down Expand Up @@ -1247,15 +1252,24 @@ pub fn add_data(writer: &mut impl ModuleWriter, data: Option<&Path>) -> Result<(
.build()
{
let file = file?;
let permissions = file.metadata()?.permissions();
#[cfg(unix)]
let mode = permissions.mode();
#[cfg(not(unix))]
let mode = 0o644;
let relative = file.path().strip_prefix(data.parent().unwrap()).unwrap();

if file.path_is_symlink() {
// Copy the actual file contents, not the link, so that you can create a
// data directory by joining different data sources
let source = fs::read_link(file.path())?;
writer.add_file(relative, source.parent().unwrap())?;
writer.add_file_with_permissions(
relative,
source.parent().unwrap(),
mode,
)?;
} else if file.path().is_file() {
writer.add_file(relative, file.path())?;
writer.add_file_with_permissions(relative, file.path(), mode)?;
} else if file.path().is_dir() {
writer.add_directory(relative)?;
} else {
Expand Down