Refactoring

This commit is contained in:
Sam Hedin 2020-06-25 20:51:53 +02:00
parent c6bbf140ed
commit a86438686e
2 changed files with 6 additions and 8 deletions

View File

@ -50,10 +50,9 @@ impl WholeStreamCommand for AutoenvTrust {
let filename = file_to_trust.to_string_lossy().to_string();
let mut allowed = Trusted::read_trusted()?;
allowed.files.insert(
filename,
Sha256::digest(&content).as_slice().to_vec()
);
allowed
.files
.insert(filename, Sha256::digest(&content).as_slice().to_vec());
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
let tomlstr = toml::to_string(&allowed).or_else(|_| {

View File

@ -38,11 +38,10 @@ impl DirectorySpecificEnvironment {
if trusted.files.get(wdirenv.to_str().unwrap_or(""))
== Some(&Sha256::digest(&content).as_slice().to_vec())
{
let content = std::str::from_utf8(&content.as_slice()).or_else(|_| {
return Ok(std::str::from_utf8(&content.as_slice()).or_else(|_| {
Err(ShellError::untagged_runtime_error(format!("Could not read {:?} as utf8 string", content)))
})?;
let content = std::fs::read_to_string(&wdirenv)?;
return Ok(content.parse::<toml::Value>().or_else(|_| {
})?
.parse::<toml::Value>().or_else(|_| {
Err(ShellError::untagged_runtime_error(format!(
"Could not parse {:?}. Is it well-formed? Each entry must be written as key = \"value\" (note the quotation marks)",
wdirenv