-
Notifications
You must be signed in to change notification settings - Fork 992
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
Update zip dependency and fix deprecation warnings #3617
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,21 @@ use std::thread; | |
use self::zip_rs::write::FileOptions; | ||
use zip as zip_rs; | ||
|
||
// Sanitize file path for normal components, excluding '/', '..', and '.' | ||
// From private function in zip crate | ||
fn path_to_string(path: &std::path::Path) -> String { | ||
let mut path_str = String::new(); | ||
for component in path.components() { | ||
if let std::path::Component::Normal(os_str) = component { | ||
if !path_str.is_empty() { | ||
path_str.push('/'); | ||
} | ||
path_str.push_str(&*os_str.to_string_lossy()); | ||
} | ||
} | ||
path_str | ||
} | ||
|
||
/// Create a zip archive from source dir and list of relative file paths. | ||
/// Permissions are set to 644 by default. | ||
pub fn create_zip(dst_file: &File, src_dir: &Path, files: Vec<PathBuf>) -> io::Result<()> { | ||
|
@@ -37,7 +52,7 @@ pub fn create_zip(dst_file: &File, src_dir: &Path, files: Vec<PathBuf>) -> io::R | |
let file_path = src_dir.join(x); | ||
if let Ok(file) = File::open(file_path.clone()) { | ||
info!("compress: {:?} -> {:?}", file_path, x); | ||
writer.get_mut().start_file_from_path(x, options)?; | ||
writer.get_mut().start_file(path_to_string(x), options)?; | ||
io::copy(&mut BufReader::new(file), &mut writer)?; | ||
// Flush the BufWriter after each file so we start then next one correctly. | ||
writer.flush()?; | ||
|
@@ -57,7 +72,7 @@ pub fn extract_files(from_archive: File, dest: &Path, files: Vec<PathBuf>) -> io | |
let mut archive = zip_rs::ZipArchive::new(from_archive).expect("archive file exists"); | ||
for x in files { | ||
if let Ok(file) = archive.by_name(x.to_str().expect("valid path")) { | ||
let path = dest.join(file.sanitized_name()); | ||
let path = dest.join(file.mangled_name()); | ||
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. Is 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. I looked at that too, but we actually want the side-effects of 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. I'm 👍 on replacing But it might be worth revisiting with a separate PR to consider replacing with From the docs referenced by @trevyn -
|
||
let parent_dir = path.parent().expect("valid parent dir"); | ||
fs::create_dir_all(&parent_dir).expect("create parent dir"); | ||
let outfile = fs::File::create(&path).expect("file created"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would just
x.to_str()
work here? We generate the path, so it shouldn't need to be sanitized with thepath_to_string
function, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path_to_string
performs extra checks thatx.to_str()
does not, like normalizing the path. I was also going for functional equivalence to what the previous function does. If you look atzip-rs
source, this is exactly what thestart_file_from_path
function does internally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍