From 94e325e64a21ba8076fc2a8d68620f9822cef938 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Fri, 16 Aug 2019 13:31:20 +0200 Subject: [PATCH 1/3] support tar.gz where files are prefixed by "./" --- src/lib.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d235661..731d874 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -338,7 +338,10 @@ impl<'a> Extract<'a> { let mut entry = archive .entries()? .filter_map(|e| e.ok()) - .find(|e| e.path().ok().filter(|p| p == file_to_extract).is_some()) + .find(|e| + e.path().ok().filter(|p| + p.strip_prefix("./").unwrap_or(p) == file_to_extract + ).is_some()) .ok_or_else(|| { Error::Update(format!( "Could not find the required path in the archive: {:?}", @@ -679,8 +682,7 @@ mod tests { cmp_content(out_file, "This is a test!"); } - #[test] - fn unpack_file_tar_gzip() { + fn unpack_file_tar_gzip_with_folder(archive_top_folder: &str, prefix_file_to_extract: &str) { let tmp_dir = TempDir::new("self_update_unpack_file_tar_gzip_src").expect("tempdir fail"); let tmp_path = tmp_dir.path(); @@ -692,7 +694,7 @@ mod tests { tmp_file.write_all(b"This is a test!").unwrap(); let mut ar = tar::Builder::new(vec![]); - ar.append_dir_all("inner_archive", &archive_src) + ar.append_dir_all(archive_top_folder, &archive_src) .expect("tar append dir all fail"); let tar_writer = ar.into_inner().expect("failed getting tar writer"); @@ -706,14 +708,22 @@ mod tests { let out_tmp = TempDir::new("self_update_unpack_file_tar_gzip_outdir").expect("tempdir fail"); let out_path = out_tmp.path(); + let file_to_extract = format!("{}temp.txt", prefix_file_to_extract); Extract::from_source(&archive_fp) - .extract_file(&out_path, "inner_archive/temp.txt") + .extract_file(&out_path, &file_to_extract) .expect("extract fail"); - let out_file = out_path.join("inner_archive/temp.txt"); + let out_file = out_path.join(&file_to_extract); assert!(out_file.exists()); cmp_content(&out_file, "This is a test!"); } + #[test] + fn unpack_file_tar_gzip() { + for folder in &[("inner_archive", "inner_archive/"), ("", ""), ("./", "")] { + unpack_file_tar_gzip_with_folder(folder.0, folder.1) + } + } + #[test] fn unpack_zip() { let tmp_dir = TempDir::new("self_update_unpack_zip_src").expect("tempdir fail"); From a27b3b04ad58383f7481b5ca35a204500c8b5484 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 20 Aug 2019 22:38:04 +0200 Subject: [PATCH 2/3] update deprecated syntax `<&std::error::Error>` with `dyn` --- examples/github.rs | 2 +- src/errors.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/github.rs b/examples/github.rs index 17f8280..04163c1 100644 --- a/examples/github.rs +++ b/examples/github.rs @@ -6,7 +6,7 @@ Example updating an executable to the latest version released via GitHub #[macro_use] extern crate self_update; -fn run() -> Result<(), Box<::std::error::Error>> { +fn run() -> Result<(), Box> { let releases = self_update::backends::github::ReleaseList::configure() .repo_owner("jaemk") .repo_name("self_update") diff --git a/src/errors.rs b/src/errors.rs index e4ef77a..67aa512 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -45,7 +45,7 @@ impl std::error::Error for Error { "Self Update Error" } - fn cause(&self) -> Option<&std::error::Error> { + fn cause(&self) -> Option<&dyn std::error::Error> { use Error::*; Some(match *self { Io(ref e) => e, From 94d5dc0e519644f0fb1921185e8a8576cc24a23f Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 20 Aug 2019 22:38:59 +0200 Subject: [PATCH 3/3] try to reduce random test failure on windows (unexpected EOF,...) --- src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 731d874..e8c34f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -646,6 +646,7 @@ mod tests { io::copy(&mut tar_writer.as_slice(), &mut e) .expect("failed writing from tar archive to gz encoder"); e.finish().expect("gz finish fail"); + archive_file.sync_all().expect("sync fs"); let out_tmp = TempDir::new("self_update_unpack_tar_gzip_outdir").expect("tempdir fail"); let out_path = out_tmp.path(); @@ -653,11 +654,11 @@ mod tests { .extract_into(&out_path) .expect("extract fail"); - let out_file = out_path.join("inner_archive/temp.txt"); + let out_file = out_path.join("inner_archive").join("temp.txt"); assert!(out_file.exists()); cmp_content(&out_file, "This is a test!"); - let out_file = out_path.join("inner_archive/temp2.txt"); + let out_file = out_path.join("inner_archive").join("temp2.txt"); assert!(out_file.exists()); cmp_content(&out_file, "This is a second test!"); } @@ -670,6 +671,7 @@ mod tests { let mut e = GzEncoder::new(&mut tmp_file, flate2::Compression::default()); e.write_all(b"This is a test!").expect("gz encode fail"); e.finish().expect("gz finish fail"); + tmp_file.sync_all().expect("sync fs"); let out_tmp = TempDir::new("self_update_unpack_file_plain_gzip_outdir").expect("tempdir fail"); @@ -704,11 +706,13 @@ mod tests { io::copy(&mut tar_writer.as_slice(), &mut e) .expect("failed writing from tar archive to gz encoder"); e.finish().expect("gz finish fail"); + archive_file.sync_all().expect("sync fs"); let out_tmp = TempDir::new("self_update_unpack_file_tar_gzip_outdir").expect("tempdir fail"); let out_path = out_tmp.path(); let file_to_extract = format!("{}temp.txt", prefix_file_to_extract); + //dbg!(&out_path, &file_to_extract); Extract::from_source(&archive_fp) .extract_file(&out_path, &file_to_extract) .expect("extract fail"); @@ -731,7 +735,7 @@ mod tests { let archive_path = tmp_path.join("archive.zip"); let archive_file = File::create(&archive_path).expect("create file fail"); - let mut zip = zip::ZipWriter::new(archive_file); + let mut zip = zip::ZipWriter::new(&archive_file); let options = zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Stored); zip.start_file("zipped.txt", options) @@ -743,6 +747,7 @@ mod tests { zip.write_all(b"This is a second test!") .expect("failed writing to second zip"); zip.finish().expect("failed finishing zip"); + archive_file.sync_all().expect("sync fs"); let out_tmp = TempDir::new("self_update_unpack_zip_outdir").expect("tempdir fail"); let out_path = out_tmp.path(); @@ -765,7 +770,7 @@ mod tests { let archive_path = tmp_path.join("archive.zip"); let archive_file = File::create(&archive_path).expect("create file fail"); - let mut zip = zip::ZipWriter::new(archive_file); + let mut zip = zip::ZipWriter::new(&archive_file); let options = zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Stored); zip.start_file("zipped.txt", options) @@ -777,6 +782,7 @@ mod tests { zip.write_all(b"This is a second test!") .expect("failed writing to second zip"); zip.finish().expect("failed finishing zip"); + archive_file.sync_all().expect("sync fs"); let out_tmp = TempDir::new("self_update_unpack_zip_outdir").expect("tempdir fail"); let out_path = out_tmp.path();