@ -1,7 +1,7 @@
use std ::{
use std ::{
ffi ::{ OsStr , OsString } ,
ffi ::{ OsStr , OsString } ,
fmt ::Write as _ ,
fmt ::Write as _ ,
fs ::{ self , OpenOptions} ,
fs ::{ self , File, OpenOptions} ,
io ::{ BufRead as _ , BufReader , Write as _ } ,
io ::{ BufRead as _ , BufReader , Write as _ } ,
ops ::Deref as _ ,
ops ::Deref as _ ,
path ::{ self , Path , PathBuf } ,
path ::{ self , Path , PathBuf } ,
@ -300,29 +300,37 @@ pub(crate) fn run(opts: Options) -> Result<()> {
fs ::create_dir_all ( & archive_dir )
fs ::create_dir_all ( & archive_dir )
. with_context ( | | format! ( "failed to create {}" , archive_dir . display ( ) ) ) ? ;
. with_context ( | | format! ( "failed to create {}" , archive_dir . display ( ) ) ) ? ;
let mut dpkg = Command ::new ( "dpkg-deb" ) ;
let archive_reader = File ::open ( archive ) . with_context ( | | {
dpkg . arg ( "--fsys-tarfile" )
format! ( "failed to open the deb package {}" , archive . display ( ) )
. arg ( archive )
. stdout ( Stdio ::piped ( ) ) ;
let mut dpkg_child = dpkg
. spawn ( )
. with_context ( | | format! ( "failed to spawn {dpkg:?}" ) ) ? ;
let Child { stdout , .. } = & mut dpkg_child ;
let stdout = stdout . take ( ) . unwrap ( ) ;
let mut archive_reader = tar ::Archive ::new ( stdout ) ;
archive_reader . unpack ( & archive_dir ) . with_context ( | | {
format! (
"failed to unpack archive {} to {}" ,
archive . display ( ) ,
archive_dir . display ( )
)
} ) ? ;
} ) ? ;
let status = dpkg_child
let mut archive_reader = ar ::Archive ::new ( archive_reader ) ;
. wait ( )
// `ar` entries are borrowed from the reader, so the reader
. with_context ( | | format! ( "failed to wait for {dpkg:?}" ) ) ? ;
// cannot implement `Iterator` (because `Iterator::Item` is not
if ! status . success ( ) {
// a GAT).
bail ! ( "{dpkg:?} exited with {status}" ) ;
//
// https://github.com/mdsteele/rust-ar/issues/15
let mut entries = 0 ;
while let Some ( entry ) = archive_reader . next_entry ( ) {
let entry = entry . with_context ( | | {
format! (
"failed to read an entry of the deb package {}" ,
archive . display ( )
)
} ) ? ;
if entry . header ( ) . identifier ( ) = = b" data.tar.xz " {
let entry_reader = xz2 ::read ::XzDecoder ::new ( entry ) ;
let mut entry_reader = tar ::Archive ::new ( entry_reader ) ;
entry_reader . unpack ( & archive_dir ) . with_context ( | | {
format! (
"failed to unpack archive {} to {}" ,
archive . display ( ) ,
archive_dir . display ( )
)
} ) ? ;
entries + = 1 ;
}
}
}
assert_eq! ( entries , 1 ) ;
let mut kernel_images = Vec ::new ( ) ;
let mut kernel_images = Vec ::new ( ) ;
let mut configs = Vec ::new ( ) ;
let mut configs = Vec ::new ( ) ;