Avoid a bit more allocation and make intentions clearer.

This commit is contained in:
r-vdp 2023-05-29 01:22:07 +02:00
parent f584494464
commit 79eecb6251
No known key found for this signature in database
3 changed files with 7 additions and 6 deletions

View file

@ -116,7 +116,7 @@ impl FileTree {
Some(go( Some(go(
maybe_subtree.unwrap_or_else(|| { maybe_subtree.unwrap_or_else(|| {
FileTree::with_status( FileTree::with_status(
new_path.to_owned(), new_path.clone(),
// We only label as managed the final path entry, // We only label as managed the final path entry,
// to label intermediate nodes as managed, we should // to label intermediate nodes as managed, we should
// call this function for every one of them separately. // call this function for every one of them separately.

View file

@ -2,6 +2,7 @@ use anyhow::{anyhow, Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::DirBuilder; use std::fs::DirBuilder;
use std::mem;
use std::path::Path; use std::path::Path;
use std::{fs, process, str}; use std::{fs, process, str};
@ -134,12 +135,12 @@ fn get_store_path(nix_build_result: process::Output) -> Result<StorePath> {
fn parse_nix_build_output(output: String) -> Result<StorePath> { fn parse_nix_build_output(output: String) -> Result<StorePath> {
let expected_output_name = "out"; let expected_output_name = "out";
let results: Vec<NixBuildOutput> = let mut results: Vec<NixBuildOutput> =
serde_json::from_str(&output).context("Error reading nix build output")?; serde_json::from_str(&output).context("Error reading nix build output")?;
if let [result] = results.as_slice() { if let [result] = results.as_mut_slice() {
if let Some(store_path) = result.outputs.get(expected_output_name) { if let Some(store_path) = result.outputs.get_mut(expected_output_name) {
return Ok(StorePath::from(store_path.to_owned())); return Ok(StorePath::from(mem::take(store_path)));
} }
anyhow::bail!("No output '{expected_output_name}' found in nix build result.") anyhow::bail!("No output '{expected_output_name}' found in nix build result.")
} }

View file

@ -424,7 +424,7 @@ fn invoke_remote_script(
path.join("bin") path.join("bin")
.join(script_name) .join(script_name)
.to_string_lossy() .to_string_lossy()
.into_owned(), .to_string(),
)) ))
.stdout(process::Stdio::inherit()) .stdout(process::Stdio::inherit())
.stderr(process::Stdio::inherit()) .stderr(process::Stdio::inherit())