src/client/pxar_backup_stream.rs: close pipe inside drop

This commit is contained in:
Dietmar Maurer 2019-05-20 11:20:33 +02:00
parent f2269d8f99
commit 2698e8a514
1 changed files with 4 additions and 3 deletions

View File

@ -22,13 +22,14 @@ use crate::tools::wrapped_reader_stream::WrappedReaderStream;
/// ///
/// Note: The currect implementation is not fully ansync and can block. /// Note: The currect implementation is not fully ansync and can block.
pub struct PxarBackupStream { pub struct PxarBackupStream {
stream: WrappedReaderStream<std::fs::File>, stream: Option<WrappedReaderStream<std::fs::File>>,
child: Option<thread::JoinHandle<()>>, child: Option<thread::JoinHandle<()>>,
} }
impl Drop for PxarBackupStream { impl Drop for PxarBackupStream {
fn drop(&mut self) { fn drop(&mut self) {
self.stream = None;
self.child.take().unwrap().join().unwrap(); self.child.take().unwrap().join().unwrap();
} }
} }
@ -52,7 +53,7 @@ impl PxarBackupStream {
let pipe = unsafe { std::fs::File::from_raw_fd(rx) }; let pipe = unsafe { std::fs::File::from_raw_fd(rx) };
let stream = crate::tools::wrapped_reader_stream::WrappedReaderStream::new(pipe); let stream = crate::tools::wrapped_reader_stream::WrappedReaderStream::new(pipe);
Ok(Self { stream, child: Some(child) }) Ok(Self { stream: Some(stream), child: Some(child) })
} }
pub fn open(dirname: &Path, all_file_systems: bool, verbose: bool) -> Result<Self, Error> { pub fn open(dirname: &Path, all_file_systems: bool, verbose: bool) -> Result<Self, Error> {
@ -70,6 +71,6 @@ impl Stream for PxarBackupStream {
type Error = Error; type Error = Error;
fn poll(&mut self) -> Poll<Option<Vec<u8>>, Error> { fn poll(&mut self) -> Poll<Option<Vec<u8>>, Error> {
self.stream.poll().map_err(Error::from) self.stream.as_mut().unwrap().poll().map_err(Error::from)
} }
} }