This commit is contained in:
Chris Hennick 2023-05-14 18:33:29 -07:00
parent 382770a947
commit 8680df6f1f
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74

View file

@ -29,12 +29,11 @@ pub struct FileOperation {
} }
impl FileOperation { impl FileOperation {
fn referenceable_name(&self) -> &str { fn referenceable_name(&self) -> String {
if let WriteDirectory(_) = self.basic && !self.name.ends_with('\\') if let BasicFileOperation::WriteDirectory(_) = self.basic {
&& !self.name.ends_with('/') { if !self.name.ends_with('\\') && !self.name.ends_with('/') {
self.name + "/" return self.name.to_owned() + "/";
} else { }
self.name
} }
} }
} }
@ -45,7 +44,7 @@ fn do_operation<T>(writer: &mut RefCell<zip_next::ZipWriter<T>>,
let name = operation.name; let name = operation.name;
match operation.basic { match operation.basic {
BasicFileOperation::WriteNormalFile {contents, mut options, ..} => { BasicFileOperation::WriteNormalFile {contents, mut options, ..} => {
if file.contents.iter().map(Vec::len).sum::<usize>() >= u32::MAX as usize { if contents.iter().map(Vec::len).sum::<usize>() >= u32::MAX as usize {
options = options.large_file(true); options = options.large_file(true);
} }
writer.borrow_mut().start_file(name, options)?; writer.borrow_mut().start_file(name, options)?;
@ -60,12 +59,12 @@ fn do_operation<T>(writer: &mut RefCell<zip_next::ZipWriter<T>>,
writer.borrow_mut().add_symlink(name, target.to_string_lossy(), options)?; writer.borrow_mut().add_symlink(name, target.to_string_lossy(), options)?;
} }
BasicFileOperation::ShallowCopy(base) => { BasicFileOperation::ShallowCopy(base) => {
let base_name = base.referenceable_name().to_owned(); let base_name = base.referenceable_name();
do_operation(writer, *base)?; do_operation(writer, *base)?;
writer.borrow_mut().shallow_copy_file(&base_name, &name)?; writer.borrow_mut().shallow_copy_file(&base_name, &name)?;
} }
BasicFileOperation::DeepCopy(base) => { BasicFileOperation::DeepCopy(base) => {
let base_name = base.referenceable_name().to_owned(); let base_name = base.referenceable_name();
do_operation(writer, *base)?; do_operation(writer, *base)?;
writer.borrow_mut().deep_copy_file(&base_name, &name)?; writer.borrow_mut().deep_copy_file(&base_name, &name)?;
} }