Skip to content

Commit

Permalink
Merge pull request #46 from Tim-Zhang/fix-clippy-for-rust-1.52
Browse files Browse the repository at this point in the history
Fix clippy for rust 1.52
  • Loading branch information
lifupan authored May 21, 2021
2 parents 5bb27a2 + 0e2430f commit 45b626e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
upper-case-acronyms-aggressive = true
5 changes: 2 additions & 3 deletions src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,8 @@ impl Cgroup {

pub const UNIFIED_MOUNTPOINT: &str = "/sys/fs/cgroup";

fn enable_controllers(controllers: &[String], path: &PathBuf) {
let mut f = path.clone();
f.push("cgroup.subtree_control");
fn enable_controllers(controllers: &[String], path: &Path) {
let f = path.join("cgroup.subtree_control");
for c in controllers {
let body = format!("+{}", c);
let _rest = fs::write(f.as_path(), body.as_bytes());
Expand Down
4 changes: 2 additions & 2 deletions src/cgroup_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ impl DeviceResourceBuilder {
access: Vec<crate::devices::DevicePermissions>,
) -> DeviceResourceBuilder {
self.cgroup.resources.devices.devices.push(DeviceResource {
allow,
devtype,
major,
minor,
devtype,
allow,
access,
});
self
Expand Down
6 changes: 3 additions & 3 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct Cpu {

/// The current state of the control group and its processes.
#[derive(Debug)]
struct CFSQuotaAndPeriod {
struct CfsQuotaAndPeriod {
quota: MaxValue,
period: u64,
}
Expand Down Expand Up @@ -284,7 +284,7 @@ impl CpuController {

impl CustomizedAttribute for CpuController {}

fn parse_cfs_quota_and_period(mut file: File) -> Result<CFSQuotaAndPeriod> {
fn parse_cfs_quota_and_period(mut file: File) -> Result<CfsQuotaAndPeriod> {
let mut content = String::new();
file.read_to_string(&mut content)
.map_err(|e| Error::with_cause(ReadFailed, e))?;
Expand All @@ -299,5 +299,5 @@ fn parse_cfs_quota_and_period(mut file: File) -> Result<CFSQuotaAndPeriod> {
.parse::<u64>()
.map_err(|e| Error::with_cause(ParseError, e))?;

Ok(CFSQuotaAndPeriod { quota, period })
Ok(CfsQuotaAndPeriod { quota, period })
}
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl fmt::Display for Error {

impl StdError for Error {
fn cause(&self) -> Option<&dyn StdError> {
#[allow(clippy::manual_map)]
match self.cause {
Some(ref x) => Some(&**x),
None => None,
Expand Down
10 changes: 5 additions & 5 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nix::sys::eventfd;
use std::fs::{self, File};
use std::io::Read;
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::path::{Path, PathBuf};
use std::path::Path;
use std::sync::mpsc::{self, Receiver};
use std::thread;

Expand All @@ -17,18 +17,18 @@ use crate::error::*;

// notify_on_oom returns channel on which you can expect event about OOM,
// if process died without OOM this channel will be closed.
pub fn notify_on_oom_v2(key: &str, dir: &PathBuf) -> Result<Receiver<String>> {
pub fn notify_on_oom_v2(key: &str, dir: &Path) -> Result<Receiver<String>> {
register_memory_event(key, dir, "memory.oom_control", "")
}

// notify_on_oom returns channel on which you can expect event about OOM,
// if process died without OOM this channel will be closed.
pub fn notify_on_oom_v1(key: &str, dir: &PathBuf) -> Result<Receiver<String>> {
pub fn notify_on_oom_v1(key: &str, dir: &Path) -> Result<Receiver<String>> {
register_memory_event(key, dir, "memory.oom_control", "")
}

// level is one of "low", "medium", or "critical"
pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result<Receiver<String>> {
pub fn notify_memory_pressure(key: &str, dir: &Path, level: &str) -> Result<Receiver<String>> {
if level != "low" && level != "medium" && level != "critical" {
return Err(Error::from_string(format!(
"invalid pressure level {}",
Expand All @@ -41,7 +41,7 @@ pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result<R

fn register_memory_event(
key: &str,
cg_dir: &PathBuf,
cg_dir: &Path,
event_name: &str,
arg: &str,
) -> Result<Receiver<String>> {
Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,9 @@ where
.map(|file| {
let bf = BufReader::new(file);
let mut v = Vec::new();
for line in bf.lines() {
if let Ok(line) = line {
let n = line.trim().parse().unwrap_or(0u64);
v.push(n);
}
for line in bf.lines().flatten() {
let n = line.trim().parse().unwrap_or(0u64);
v.push(n);
}
v.into_iter().map(CgroupPid::from).collect()
})
Expand All @@ -383,7 +381,7 @@ where

// remove_dir aims to remove cgroup path. It does so recursively,
// by removing any subdirectories (sub-cgroups) first.
fn remove_dir(dir: &PathBuf) -> Result<()> {
fn remove_dir(dir: &Path) -> Result<()> {
// try the fast path first.
if fs::remove_dir(dir).is_ok() {
return Ok(());
Expand Down

0 comments on commit 45b626e

Please sign in to comment.