From adaacd90f074d85ddfc96e1bc93efa1a6f6b0f4a Mon Sep 17 00:00:00 2001 From: Chris Hennick Date: Sat, 29 Apr 2023 13:58:17 -0700 Subject: [PATCH] Wrap files in Rc> --- src/write.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/write.rs b/src/write.rs index 3962b80a..f9d49fa7 100644 --- a/src/write.rs +++ b/src/write.rs @@ -14,6 +14,7 @@ use std::io; use std::io::prelude::*; use std::io::{BufReader, SeekFrom}; use std::mem; +use std::rc::Rc; #[cfg(any( feature = "deflate", @@ -49,6 +50,8 @@ enum GenericZipWriter { pub(crate) mod zip_writer { use super::*; use std::cell::RefCell; + use std::rc::Rc; + /// ZIP archive generator /// /// Handles the bookkeeping involved in building an archive, and provides an @@ -79,7 +82,7 @@ pub(crate) mod zip_writer { /// ``` pub struct ZipWriter { pub(super) inner: GenericZipWriter, - pub(super) files: Vec>, + pub(super) files: Vec>>, pub(super) stats: ZipWriterStats, pub(super) writing_to_file: bool, pub(super) writing_to_extra_field: bool, @@ -283,7 +286,9 @@ impl ZipWriter { } let files = (0..number_of_files) - .map(|_| central_header_to_zip_file(&mut readwriter, archive_offset).map(RefCell::new)) + .map(|_| central_header_to_zip_file(&mut readwriter, archive_offset) + .map(RefCell::new) + .map(Rc::new)) .collect::, _>>()?; let _ = readwriter.seek(SeekFrom::Start(directory_start)); // seek directory_start to overwrite it @@ -431,7 +436,7 @@ impl ZipWriter { self.stats.bytes_written = 0; self.stats.hasher = Hasher::new(); - self.files.push(RefCell::new(file)); + self.files.push(Rc::new(RefCell::new(file))); } Ok(()) @@ -919,7 +924,7 @@ impl ZipWriter { let mut dest_data = src_data.to_owned(); drop(src_data); dest_data.file_name = dest_name.into(); - self.files.push(RefCell::new(dest_data)); + self.files.push(Rc::new(RefCell::new(dest_data))); Ok(()) } }