Cleanup mod async_extracter

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-11 20:13:10 +10:00
parent 7b52eaad5b
commit 57b40d809e
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -5,7 +5,7 @@ use std::path::Path;
use bytes::Bytes; use bytes::Bytes;
use futures_util::stream::{Stream, StreamExt}; use futures_util::stream::{Stream, StreamExt};
use scopeguard::{guard, Always, ScopeGuard}; use scopeguard::{guard, ScopeGuard};
use tempfile::tempfile; use tempfile::tempfile;
use tokio::{ use tokio::{
sync::mpsc, sync::mpsc,
@ -13,7 +13,7 @@ use tokio::{
}; };
use super::{extracter::*, readable_rx::*}; use super::{extracter::*, readable_rx::*};
use crate::{BinstallError, PkgFmt, TarBasedFmt}; use crate::{BinstallError, TarBasedFmt};
pub(crate) enum Content { pub(crate) enum Content {
/// Data to write to file /// Data to write to file
@ -61,45 +61,7 @@ impl<T: Debug + Send + 'static> AsyncExtracterInner<T> {
) -> Self { ) -> Self {
let (tx, rx) = mpsc::channel::<Content>(100); let (tx, rx) = mpsc::channel::<Content>(100);
let handle = spawn_blocking(move || { let handle = spawn_blocking(move || f(rx));
f(rx)
/*
fs::create_dir_all(path.parent().unwrap())?;
match fmt {
PkgFmt::Bin => {
let mut file = fs::File::create(&path)?;
// remove it unless the operation isn't aborted and no write
// fails.
let remove_guard = guard(&path, |path| {
fs::remove_file(path).ok();
});
Self::read_into_file(&mut file, &mut rx)?;
// Operation isn't aborted and all writes succeed,
// disarm the remove_guard.
ScopeGuard::into_inner(remove_guard);
}
PkgFmt::Zip => {
let mut file = tempfile()?;
Self::read_into_file(&mut file, &mut rx)?;
// rewind it so that we can pass it to unzip
file.rewind()?;
unzip(file, &path)?;
}
_ => {
extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt, &path, filter)?
}
}
Ok(())
*/
});
Self { handle, tx } Self { handle, tx }
} }
@ -233,9 +195,7 @@ where
// rewind it so that we can pass it to unzip // rewind it so that we can pass it to unzip
file.rewind()?; file.rewind()?;
unzip(file, &path)?; unzip(file, &path)
Ok(())
}) })
.await .await
} }
@ -259,9 +219,7 @@ where
extract_impl(stream, move |mut rx| { extract_impl(stream, move |mut rx| {
fs::create_dir_all(path.parent().unwrap())?; fs::create_dir_all(path.parent().unwrap())?;
extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt.into(), &path, filter)?; extract_compressed_from_readable(ReadableRx::new(&mut rx), fmt.into(), &path, filter)
Ok(())
}) })
.await .await
} }
@ -284,9 +242,7 @@ where
fmt.into(), fmt.into(),
&path, &path,
None, None,
)?; )
Ok(())
}) })
.await .await
} }