From ad5ed84d918b4736ebf8b0d10f7101294cfb1e8c Mon Sep 17 00:00:00 2001 From: Jamie Winsor Date: Thu, 17 Mar 2016 13:17:17 -0700 Subject: [PATCH] fix bug where all data blocks were not extracted to file --- libraries/libarchive/src/writer.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/libarchive/src/writer.rs b/libraries/libarchive/src/writer.rs index 14e41b80..975e8eb3 100644 --- a/libraries/libarchive/src/writer.rs +++ b/libraries/libarchive/src/writer.rs @@ -144,16 +144,20 @@ impl Disk { let mut offset = 0; unsafe { - match ffi::archive_read_data_block(reader.handle(), &mut buff, &mut size, &mut offset) { - ffi::ARCHIVE_EOF => Ok(size), - ffi::ARCHIVE_OK => { - if ffi::archive_write_data_block(self.handle, buff, size, offset) < 0 { - Err(ArchiveError::from(self as &Handle)) - } else { - Ok(size) + loop { + match ffi::archive_read_data_block(reader.handle(), + &mut buff, + &mut size, + &mut offset) { + ffi::ARCHIVE_EOF => return Ok(size), + ffi::ARCHIVE_OK => { + if ffi::archive_write_data_block(self.handle, buff, size, offset) != + ffi::ARCHIVE_OK as isize { + return Err(ArchiveError::from(self as &Handle)); + } } + _ => return Err(ArchiveError::from(reader as &Handle)), } - _ => Err(ArchiveError::from(reader as &Handle)), } } }