From 9945a08434dc51d480d1e9303ee2fa7b5e823d7d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 8 Jan 2022 20:35:58 -0500 Subject: simplify --- src/shell/history/mod.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs index b2ad9d0..b7b33b8 100644 --- a/src/shell/history/mod.rs +++ b/src/shell/history/mod.rs @@ -492,11 +492,13 @@ async fn run_pipeline( nix::unistd::close(from_w)?; // Safety: to_w was just opened above, was not used until now, and can't - // be used after this because we rebound the variable - let mut to_w = unsafe { async_std::fs::File::from_raw_fd(to_w) }; - to_w.write_all(&bincode::serialize(pipeline)?).await?; - to_w.write_all(&env.as_bytes()).await?; - drop(to_w); + // be used after this because from_raw_fd takes it by move + write_env( + unsafe { async_std::fs::File::from_raw_fd(to_w) }, + pipeline, + env, + ) + .await?; let (read_w, read_r) = async_std::channel::unbounded(); let new_read = move || { @@ -579,3 +581,13 @@ async fn run_pipeline( } } } + +async fn write_env( + mut to_w: async_std::fs::File, + pipeline: &str, + env: &Env, +) -> anyhow::Result<()> { + to_w.write_all(&bincode::serialize(pipeline)?).await?; + to_w.write_all(&env.as_bytes()).await?; + Ok(()) +} -- cgit v1.2.3-54-g00ecf