From 17af83927702550fb31b87cdd4d7e67f231560e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lupien=20=28Jojolepro=29?= Date: Fri, 22 Feb 2019 20:02:17 -0500 Subject: [PATCH 1/3] Fix recursive zip extraction. --- src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 05eb998..3a02a65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -353,9 +353,19 @@ impl<'a> Extract<'a> { let mut archive = zip::ZipArchive::new(source)?; for i in 0..archive.len() { let mut file = archive.by_index(i)?; - let path = into_dir.join(file.name()); - let mut output = fs::File::create(path)?; - io::copy(&mut file, &mut output)?; + let outpath = into_dir.join(file.sanitized_name()); + + if (&*file.name()).ends_with('/') { + fs::create_dir_all(&outpath).unwrap(); + } else { + if let Some(p) = outpath.parent() { + if !p.exists() { + fs::create_dir_all(&p).unwrap(); + } + } + let mut outfile = fs::File::create(&outpath).unwrap(); + io::copy(&mut file, &mut outfile).unwrap(); + } } } }; From 9ac8bf1f6551468a905260d2016ab6bd15655493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lupien=20=28Jojolepro=29?= Date: Fri, 22 Feb 2019 22:54:40 -0500 Subject: [PATCH 2/3] Replace unwraps by ?. Simplify is directory check in zip decompression. --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3a02a65..935f318 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -355,16 +355,16 @@ impl<'a> Extract<'a> { let mut file = archive.by_index(i)?; let outpath = into_dir.join(file.sanitized_name()); - if (&*file.name()).ends_with('/') { - fs::create_dir_all(&outpath).unwrap(); + if outpath.is_dir() { + fs::create_dir_all(&outpath)?; } else { if let Some(p) = outpath.parent() { if !p.exists() { - fs::create_dir_all(&p).unwrap(); + fs::create_dir_all(&p)?; } } - let mut outfile = fs::File::create(&outpath).unwrap(); - io::copy(&mut file, &mut outfile).unwrap(); + let mut outfile = fs::File::create(&outpath)?; + io::copy(&mut file, &mut outfile)?; } } } From 2898af914ea8261923525213d0d6cfb79140c55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lupien=20=28Jojolepro=29?= Date: Fri, 22 Feb 2019 22:56:37 -0500 Subject: [PATCH 3/3] Rollback to old directory check. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 935f318..fb4a264 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -355,7 +355,7 @@ impl<'a> Extract<'a> { let mut file = archive.by_index(i)?; let outpath = into_dir.join(file.sanitized_name()); - if outpath.is_dir() { + if (&*file.name()).ends_with('/') { fs::create_dir_all(&outpath)?; } else { if let Some(p) = outpath.parent() {