Skip to content

Commit

Permalink
Work on warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LeChatP committed Sep 10, 2024
1 parent db2fdfd commit c16417a
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 114 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: cargo xtask dependencies -dip sudo

- name: run tests with coverage
run: cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --exclude-files build.rs -e xtask --out Xml
run: cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --exclude-files build.rs xtask/src/* -e xtask --out Xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand All @@ -40,7 +40,7 @@ jobs:
flags: unittests

- name: run tests with coverage as Admin
run: sudo -E /usr/local/cargo/bin/cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --exclude-files build.rs -e xtask --out Xml
run: sudo -E /usr/local/cargo/bin/cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --exclude-files build.rs xtask/src/* -e xtask --out Xml

- name: Upload coverage reports to Codecov as Admin
uses: codecov/codecov-action@v3
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ path = "src/chsr/main.rs"
default = ["finder"]
finder = ["dep:pcre2", "rar-common/pcre2", "rar-common/finder"]

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(tarpaulin_include)'] }


[build-dependencies]
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
Expand Down
86 changes: 0 additions & 86 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use pcre2::bytes::RegexBuilder;
use serde_json::Value;
use std::error::Error;
use std::fs::File;
use std::io::{BufRead, BufReader, Write};

use std::path::Path;
use std::process::Command;

fn write_version<'a>(f: &'a mut File, doc: &'a Value) -> Result<&'a str, Box<dyn Error>> {
let package_version = doc
Expand Down Expand Up @@ -39,90 +37,6 @@ fn set_cargo_version(package_version: &str, file: &str) -> Result<(), Box<dyn Er
Ok(())
}

fn set_pkgbuild_version(package_version: &str, file: &str) -> Result<(), Box<dyn Error>> {
let pkgbuild = File::open(std::path::Path::new(file)).expect("PKGBUILD not found");
let reader = BufReader::new(pkgbuild);
let lines = reader.lines().map(|l| l.unwrap()).collect::<Vec<String>>();
let mut pkgbuild = File::create(std::path::Path::new(file)).expect("PKGBUILD not found");
for line in lines {
if line.starts_with("pkgver") {
writeln!(pkgbuild, "pkgver={}", package_version)?;
} else {
writeln!(pkgbuild, "{}", line)?;
}
}
pkgbuild.sync_all()?;
Ok(())
}

fn write_doc(f: &mut File) -> Result<(), Box<dyn Error>> {
let docresp = reqwest::blocking::get(
"https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/plain/man7/capabilities.7",
)
.expect("request failed");
let haystack = docresp.text()?;

//write to new temporary file
let temp = std::path::Path::new("temp.7");
let mut tempf = File::create(temp)?;
tempf.write_all(haystack.as_bytes())?;
tempf.flush()?;
//now execute man command to convert to ascii
let res = String::from_utf8(
Command::new("/usr/bin/man")
.args(["--nh", "--nj", "-al", "-P", "/usr/bin/cat", "temp.7"])
.output()?
.stdout,
)?;
//delete temp file
std::fs::remove_file(temp)?;
//now parse the output
let mut re = RegexBuilder::new();
re.multi_line(true);
let re = re.build(r"^ (CAP_[A-Z_]+)\K((?!^ CAP_[A-Z_]+|^ Past).|\R)+")?;
let spacere = regex::Regex::new(r" +")?;
f.write_all(
r#"use capctl::Cap;
"#
.as_bytes(),
)?;
f.write_all(
r#"#[rustfmt::skip]
#[allow(clippy::all)]
pub fn get_capability_description(cap : &Cap) -> &'static str {
match *cap {
"#
.as_bytes(),
)?;
let mut caplist = Vec::new();
for cap in re.captures_iter(res.as_bytes()) {
let cap = cap?;
let name = std::str::from_utf8(cap.get(1).unwrap().as_bytes())?;
if caplist.contains(&name) {
continue;
}
caplist.push(name);
let mut desc = std::string::String::from_utf8(cap.get(0).unwrap().as_bytes().to_vec())?;
desc = spacere.replace_all(&desc, " ").to_string();
let desc = desc.trim().to_string();
f.write_all(
format!(
" Cap::{} => r#{:#?}#,\n",
name.replace("CAP_", ""),
desc.replace('\n', "")
)
.as_bytes(),
)?;
}
f.write_all(
r#" _ => "Unknown capability",
}
}"#
.as_bytes(),
)?;
Ok(())
}

fn set_readme_version(package_version: &str, file: &str) -> Result<(), Box<dyn Error>> {
let readme = File::open(std::path::Path::new(file)).expect("README.md not found");
let reader = BufReader::new(readme);
Expand Down
5 changes: 4 additions & 1 deletion rar-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ lazy_static = "1.4.0"

[features]
pcre2 = ["dep:pcre2"]
finder = ["dep:glob"]
finder = ["dep:glob"]

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(tarpaulin_include)'] }
2 changes: 1 addition & 1 deletion rar-common/src/database/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fn match_args(input_args: &[String], role_args: &[String]) -> Result<CmdMin, Box
if commandline != role_args {
debug!("test regex");
return evaluate_regex_cmd(role_args, commandline).inspect_err(|e| {
debug!("No match for args {:?}", input_args);
debug!("{:?},No match for args {:?}", e, input_args);
});

Check warning on line 361 in rar-common/src/database/finder.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> rar-common/src/database/finder.rs:359:9 | 359 | / return evaluate_regex_cmd(role_args, commandline).inspect_err(|e| { 360 | | debug!("{:?},No match for args {:?}", e, input_args); 361 | | }); | |__________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `#[warn(clippy::needless_return)]` on by default help: remove `return` | 359 ~ evaluate_regex_cmd(role_args, commandline).inspect_err(|e| { 360 + debug!("{:?},No match for args {:?}", e, input_args); 361 ~ }) |
} else {
return Ok(CmdMin::Match);

Check warning on line 363 in rar-common/src/database/finder.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> rar-common/src/database/finder.rs:363:9 | 363 | return Ok(CmdMin::Match); | ^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 363 - return Ok(CmdMin::Match); 363 + Ok(CmdMin::Match) |
Expand Down
15 changes: 1 addition & 14 deletions rar-common/src/database/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ impl<'de> Deserialize<'de> for EnvKey {
}
}

#[cfg(test)]
impl SPathOptions {
fn new(behavior: PathBehavior) -> Self {
let mut res = SPathOptions::default();
Expand Down Expand Up @@ -611,10 +612,6 @@ impl OptStack {
}
}

fn get_opt(&self, level: Level) -> Option<Rc<RefCell<Opt>>> {
self.stack[level as usize].to_owned()
}

fn find_in_options<F: Fn(&Opt) -> Option<(Level, V)>, V>(&self, f: F) -> Option<(Level, V)> {
for opt in self.stack.iter().rev() {
if let Some(opt) = opt.to_owned() {
Expand Down Expand Up @@ -1091,16 +1088,6 @@ impl OptStack {
.unwrap_or((Level::None, STimeout::default()))
}

fn get_lowest_level(&self) -> Level {
if self.task.is_some() {
Level::Task
} else if self.role.is_some() {
Level::Role
} else {
Level::Global
}
}

pub fn to_opt(&self) -> Opt {
let mut res = Opt::default();
let (final_behavior, final_add, final_sub) = self.get_final_path();
Expand Down
3 changes: 3 additions & 0 deletions src/sr/pam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ use rar_common::{

use self::rpassword::Terminal;

#[allow(dead_code, reason ="This file is part of sudo-rs.")]
mod cutils;
#[allow(dead_code, reason ="This file is part of sudo-rs.")]
mod rpassword;
#[allow(dead_code, reason ="This file is part of sudo-rs.")]
mod securemem;

#[cfg(not(test))]
Expand Down
3 changes: 3 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ default = ["cli", "ebpf", "deploy"]
cli = []
ebpf = []
deploy = []

[lints.rust]
dead-code = { level = "allow" }
5 changes: 0 additions & 5 deletions xtask/src/deploy/arch.rs

This file was deleted.

2 changes: 0 additions & 2 deletions xtask/src/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use clap::Parser;

use crate::{install::Profile, util::OsTarget};

mod arch;
mod debian;
mod redhat;

Expand Down Expand Up @@ -42,7 +41,6 @@ pub fn deploy(opts: &MakeOptions) -> Result<(), anyhow::Error> {
for target in targets {
match target {
OsTarget::Debian => debian::make_deb(opts.os.clone(), opts.profile, &opts.priv_bin)?,
OsTarget::ArchLinux => arch::make_pkg(opts.profile)?,
OsTarget::RedHat => redhat::make_rpm(opts.os.clone(), opts.profile, &opts.priv_bin)?,
_ => anyhow::bail!("Unsupported OS target"),
}
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/install/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn install(
.as_ref()
.or(priv_bin.as_ref())
.context("Privileged binary is required")
.map_err(|e| {
.map_err(|_| {
return anyhow::Error::msg(format!(
"Please run {} as an administrator.",
current_exe()
Expand Down
4 changes: 2 additions & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum Command {
#[cfg(feature = "deploy")]
Deploy(deploy::MakeOptions),
}
fn subsribe(tool: &str) {
fn subsribe() {
use std::io;
tracing_subscriber::fmt()
.with_max_level(Level::DEBUG)
Expand All @@ -46,7 +46,7 @@ fn subsribe(tool: &str) {
}

fn main() {
subsribe("xtask");
subsribe();
let opts = Options::parse();
use Command::*;
let ret = match opts.command {
Expand Down

0 comments on commit c16417a

Please sign in to comment.