From 6f120223b272ae4e00fbce1abb6a884ff53154a5 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:17:03 -0700 Subject: [PATCH] fix: `deep_copy_file` no longer allows overwriting an existing file, to match the behavior of `shallow_copy_file` --- src/write.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/write.rs b/src/write.rs index d4928d0dc..e19cb64a4 100644 --- a/src/write.rs +++ b/src/write.rs @@ -663,8 +663,8 @@ impl ZipWriter { /// widely-compatible archive compared to [Self::shallow_copy_file]. Does not copy alignment. pub fn deep_copy_file(&mut self, src_name: &str, dest_name: &str) -> ZipResult<()> { self.finish_file()?; - if src_name == dest_name { - return Err(InvalidArchive("Trying to copy a file to itself")); + if src_name == dest_name || self.files.contains_key(dest_name) { + return Err(InvalidArchive("That file already exists")); } let write_position = self.inner.get_plain().stream_position()?; let src_index = self.index_by_name(src_name)?;