mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-02 18:20:03 +00:00
Cleanup mod async_extracter
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
7b52eaad5b
commit
57b40d809e
1 changed files with 6 additions and 50 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue