Skip to content

Commit

Permalink
style(Judger): 🎨 manual cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Jun 30, 2024
1 parent 1c79d56 commit 07638bb
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 336 deletions.
528 changes: 230 additions & 298 deletions judger/src/filesystem/adapter/fuse.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion judger/src/filesystem/adapter/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
{
ReplyAttr {
ttl: TTL,
attr: file_attr(req, &entry, inode),
attr: file_attr(req, entry, inode),
}
}

Expand Down
9 changes: 2 additions & 7 deletions judger/src/filesystem/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where
}
pub(super) fn get_symlink(&self) -> Option<&OsStr> {
if let Self::SymLink(x) = self {
return Some(&*x);
return Some(x);
}
None
}
Expand Down Expand Up @@ -136,12 +136,7 @@ where
pub async fn write(&mut self, offset: u64, data: &[u8], resource: &Resource) -> Option<u32> {
// FIXME: consume logic should move somewhere else
let required_size = data.len() as u64 + offset;
if resource
.comsume_other(required_size.saturating_sub(self.get_size()))
.is_none()
{
return None;
}
resource.comsume_other(required_size.saturating_sub(self.get_size()))?;

match self {
Self::MemFile(block) => Some(block.write(offset, data).await.unwrap()),
Expand Down
2 changes: 1 addition & 1 deletion judger/src/filesystem/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ID_MIN: usize = 1;
const MAX_ID_CAPACITY: u32 = 1 << 31;

/// convert a path to internal path(prefixes on the tree)
pub fn to_internal_path<'a>(path: &'a Path) -> impl Iterator<Item = &OsStr> + 'a {
pub fn to_internal_path(path: &Path) -> impl Iterator<Item = &OsStr> {
path.components().filter_map(|component| match component {
Component::Prefix(x) => unreachable!("Windows only: {:?}", x),
Component::RootDir | Component::CurDir | Component::ParentDir => None,
Expand Down
14 changes: 7 additions & 7 deletions judger/src/language/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ where
impl Plugin<File> {
pub async fn new(path: impl AsRef<Path> + Clone) -> Result<Self> {
let template = Arc::new(Template::new(path.clone()).await?);
let spec_source = template.read_by_path("spec.toml").await.expect(&format!(
"sepc.toml not found in plugin {}",
path.as_ref().display()
));
let spec_source = template
.read_by_path("spec.toml")
.await
.unwrap_or_else(|| panic!("sepc.toml not found in plugin {}", path.as_ref().display()));
let spec = Arc::new(Spec::from_str(&spec_source.to_string_lossy()));

Ok(Self { spec, template })
Expand Down Expand Up @@ -157,10 +157,10 @@ where

let mem_cpu = (args.mem, args.cpu);
let mode = args.mode;
let mut io = args.input.into_iter().zip(args.output.into_iter());
let testcases = args.input.into_iter().zip(args.output.into_iter());
Box::pin(try_stream! {
while let Some((input,output))=io.next(){
let judger = runner.judge(mem_cpu.clone(), input).await?;
for (input,output) in testcases{
let judger = runner.judge(mem_cpu, input).await?;

yield judger.get_result(&output, mode);
if judger.get_code(&output, mode)!=StatusCode::Accepted{
Expand Down
14 changes: 2 additions & 12 deletions judger/src/language/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,8 @@ impl Spec {
output: raw.compile.output_limit.unwrap(),
walltime: Duration::from_nanos(raw.compile.walltime.unwrap()),
},
compile_command: raw
.compile
.command
.iter()
.map(|x| OsString::from(x))
.collect(),
judge_command: raw
.judge
.command
.iter()
.map(|x| OsString::from(x))
.collect(),
compile_command: raw.compile.command.iter().map(OsString::from).collect(),
judge_command: raw.judge.command.iter().map(OsString::from).collect(),
file: OsString::from(raw.file),
judge_cpu_factor: CpuFactor {
kernel: raw.judge.kernel_mem.unwrap(),
Expand Down
12 changes: 4 additions & 8 deletions judger/src/sandbox/monitor/mem_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ async fn monitor(cgroup: Arc<Cgroup>, cpu: Cpu) -> MonitorKind {
});

select! {
_ = cpu_future=>{
return MonitorKind::Cpu;
},
_ = oom_signal.wait()=>{
return MonitorKind::Memory;
}
_ = cpu_future=> MonitorKind::Cpu,
_ = oom_signal.wait()=> MonitorKind::Memory
}
}

Expand Down Expand Up @@ -109,8 +105,8 @@ impl super::Monitor for Monitor {
///
///
/// 2. Actively limit(notify) cpu resource is achieved by polling the cgroup,
/// the delay require special attention, it is only guaranteed
/// to below limitation provided + [`MONITOR_ACCURACY`].
/// the delay require special attention, it is only guaranteed
/// to below limitation provided + [`MONITOR_ACCURACY`].
///
/// This method is cancellation safe
async fn wait_exhaust(&mut self) -> MonitorKind {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions judger/src/sandbox/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
//! ```
mod corpse;
mod lifetime;
mod nsjail;
mod process;

use super::*;

pub use corpse::*;
pub use process::*;
pub use lifetime::*;

0 comments on commit 07638bb

Please sign in to comment.