-
Notifications
You must be signed in to change notification settings - Fork 82
feat: implement binary prefix detection behavior in packaging #1658
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
5845966
5d0a778
2ba1571
6a2ac3f
7726242
e49dd65
eb72ea6
85a9a24
dc2a348
8919697
36ac234
8f429a3
efeb817
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
use crate::metadata::Output; | ||
use fs_err as fs; | ||
#[cfg(target_family = "unix")] | ||
use fs_err::os::unix::fs::symlink; | ||
Check failure on line 6 in src/packaging/file_mapper.rs
|
||
use std::{ | ||
collections::HashSet, | ||
path::{Component, Path, PathBuf}, | ||
|
@@ -220,63 +220,55 @@ | |
|
||
let metadata = fs::symlink_metadata(path)?; | ||
|
||
// make absolute symlinks relative | ||
if metadata.is_symlink() { | ||
// Handle symlinks: make absolute symlinks relative and copy the link | ||
if metadata.file_type().is_symlink() { | ||
if target_platform.is_windows() { | ||
tracing::warn!("Symlinks need administrator privileges on Windows"); | ||
tracing::warn!("Symlink creation on Windows requires administrator privileges"); | ||
} | ||
|
||
if let Result::Ok(link) = fs::read_link(path) { | ||
tracing::trace!("Copying link: {:?} -> {:?}", path, link); | ||
} else { | ||
tracing::warn!("Could not read link at {:?}", path); | ||
} | ||
|
||
#[cfg(target_family = "unix")] | ||
fs::read_link(path).and_then(|target| { | ||
if target.is_absolute() && target.starts_with(prefix) { | ||
let rel_target = pathdiff::diff_paths( | ||
target, | ||
path.parent().ok_or(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"Could not get parent directory", | ||
))?, | ||
) | ||
.ok_or(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
"Could not get relative path", | ||
))?; | ||
|
||
tracing::trace!( | ||
"Making symlink relative {:?} -> {:?}", | ||
dest_path, | ||
rel_target | ||
); | ||
symlink(&rel_target, &dest_path).map_err(|e| { | ||
tracing::error!( | ||
"Could not create symlink from {:?} to {:?}: {:?}", | ||
rel_target, | ||
dest_path, | ||
e | ||
); | ||
e | ||
})?; | ||
} else { | ||
if target.is_absolute() { | ||
tracing::warn!("Symlink {:?} points outside of the prefix", path); | ||
// Read the link target | ||
match fs::read_link(path) { | ||
Ok(mut target) => { | ||
// If absolute and within the build prefix, make it relative | ||
if target.is_absolute() && target.starts_with(prefix) { | ||
if let Some(parent) = path.parent() { | ||
if let Some(rel) = pathdiff::diff_paths(&target, parent) { | ||
target = rel; | ||
} | ||
} | ||
} | ||
// Create the symlink at dest_path | ||
#[cfg(unix)] | ||
{ | ||
if let Err(e) = fs::os::unix::fs::symlink(&target, &dest_path) { | ||
zelosleone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tracing::warn!( | ||
"Failed to create symlink {:?} -> {:?}: {:?}", | ||
dest_path, | ||
target, | ||
e | ||
); | ||
} | ||
} | ||
#[cfg(windows)] | ||
{ | ||
let res = if metadata.file_type().is_dir() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the metadata is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just checked and i think we can use |
||
std::os::windows::fs::symlink_dir(&target, &dest_path) | ||
zelosleone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
std::os::windows::fs::symlink_file(&target, &dest_path) | ||
}; | ||
if let Err(e) = res { | ||
tracing::warn!( | ||
"Failed to create symlink {:?} -> {:?}: {:?}", | ||
dest_path, | ||
target, | ||
e | ||
); | ||
} | ||
} | ||
symlink(&target, &dest_path).map_err(|e| { | ||
tracing::error!( | ||
"Could not create symlink from {:?} to {:?}: {:?}", | ||
target, | ||
dest_path, | ||
e | ||
); | ||
e | ||
})?; | ||
} | ||
Result::Ok(()) | ||
})?; | ||
Err(e) => { | ||
tracing::warn!("Failed to read symlink {:?}: {:?}", path, e); | ||
} | ||
} | ||
Ok(Some(dest_path)) | ||
} else if metadata.is_dir() { | ||
// skip directories for now | ||
|
Uh oh!
There was an error while loading. Please reload this page.