mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
fix 7z BadSignature error when compressing and then listing
Signed-off-by: tommady <tommady@users.noreply.github.com>
This commit is contained in:
parent
c3b89b038d
commit
fe4ac77ef5
@ -171,11 +171,11 @@ where
|
||||
}
|
||||
|
||||
/// List contents of `archive_path`, returning a vector of archive entries
|
||||
pub fn list_archive(
|
||||
archive_path: &Path,
|
||||
password: Option<&[u8]>,
|
||||
) -> Result<impl Iterator<Item = crate::Result<FileInArchive>>> {
|
||||
let reader = fs::File::open(archive_path)?;
|
||||
pub fn list_archive<R>(reader: R, password: Option<&[u8]>) -> Result<impl Iterator<Item = crate::Result<FileInArchive>>>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
||||
// let reader = fs::File::open(archive_path)?;
|
||||
|
||||
let mut files = Vec::new();
|
||||
|
||||
|
@ -122,7 +122,10 @@ pub fn list_archive_contents(
|
||||
}
|
||||
}
|
||||
|
||||
Box::new(archive::sevenz::list_archive(archive_path, password)?)
|
||||
let mut vec = vec![];
|
||||
io::copy(&mut reader, &mut vec)?;
|
||||
|
||||
Box::new(archive::sevenz::list_archive(io::Cursor::new(vec), password)?)
|
||||
}
|
||||
Gzip | Bzip | Bzip3 | Lz4 | Lzma | Snappy | Zstd | Brotli => {
|
||||
unreachable!("Not an archive, should be validated before calling this function.");
|
||||
|
@ -1065,3 +1065,27 @@ fn fail_when_compressing_archive_as_the_second_extension() {
|
||||
.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sevenz_list_should_not_failed() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let root_path = temp_dir.path();
|
||||
let src_files_path = root_path.join("src_files");
|
||||
fs::create_dir_all(&src_files_path).unwrap();
|
||||
|
||||
let archive = root_path.join("archive.7z.gz");
|
||||
crate::utils::cargo_bin()
|
||||
.arg("compress")
|
||||
.arg("--yes")
|
||||
.arg(fs::File::create(src_files_path.join("README.md")).unwrap().path())
|
||||
.arg(&archive)
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
crate::utils::cargo_bin()
|
||||
.arg("list")
|
||||
.arg("--yes")
|
||||
.arg(&archive)
|
||||
.assert()
|
||||
.success();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user