Avoid running remote topgrade on the current host (fix #804) (#807)

This commit is contained in:
Roey Darwish Dror
2021-12-06 13:31:05 +02:00
committed by GitHub
parent 10d362eab4
commit e9d809ddb0
3 changed files with 32 additions and 11 deletions

11
Cargo.lock generated
View File

@@ -1668,6 +1668,16 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "sys-info"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "tar"
version = "0.4.37"
@@ -1843,6 +1853,7 @@ dependencies = [
"shellexpand",
"structopt",
"strum 0.22.0",
"sys-info",
"tempfile",
"thiserror",
"tokio",

View File

@@ -33,6 +33,7 @@ cfg-if = "1.0.0"
tokio = { version = "1.5.0", features = ["process", "rt-multi-thread"] }
futures = "0.3.14"
regex = "1.5.3"
sys-info = "0.9"
[target.'cfg(target_os = "macos")'.dependencies]
notify-rust = "4.5.0"

View File

@@ -1,19 +1,22 @@
use super::utils::editor;
use std::collections::BTreeMap;
use std::fs::write;
use std::path::PathBuf;
use std::process::Command;
use std::{env, fs};
use anyhow::Result;
use directories::BaseDirs;
use log::{debug, LevelFilter};
use pretty_env_logger::formatted_timed_builder;
use regex::Regex;
use serde::Deserialize;
use std::collections::BTreeMap;
use std::fs::write;
use std::path::PathBuf;
use std::process::Command;
use std::{env, fs};
use structopt::StructOpt;
use strum::{EnumIter, EnumString, EnumVariantNames, IntoEnumIterator, VariantNames};
use sys_info::hostname;
use which_crate::which;
use super::utils::editor;
pub static EXAMPLE_CONFIG: &str = include_str!("../config.example.toml");
#[allow(unused_macros)]
@@ -826,10 +829,16 @@ impl Config {
str_value!(linux, emerge_update_flags);
pub fn should_execute_remote(&self, remote: &str) -> bool {
self.opt
.remote_host_limit
.as_ref()
.map(|h| h.is_match(remote))
.unwrap_or(true)
if let Ok(hostname) = hostname() {
if remote == hostname {
return false;
}
}
if let Some(limit) = self.opt.remote_host_limit.as_ref() {
return limit.is_match(remote);
}
true
}
}