Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Aug 21, 2024
1 parent 1318e4b commit 40c6a83
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 75 deletions.
18 changes: 9 additions & 9 deletions judger/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub enum Error {
Io(#[from] std::io::Error),
#[error("sandbox error: {0}")]
Sandbox(#[from] SandboxError),
/// the program is running on a 32 bit platform,
/// and have a object reached [`u32::MAX`]
/// the program is running on a 32-bit platform,
/// and have an object reached [`u32::MAX`]
#[error("32 bit problem")]
Platform,
}
Expand All @@ -23,20 +23,20 @@ impl From<Error> for Status {

#[derive(thiserror::Error, Debug)]
pub enum ClientError {
#[error("invaild secret")]
InvaildSecret,
#[error("invaild language uuid")]
InvaildLanguageUuid,
#[error("invalid secret")]
InvalidSecret,
#[error("invalid language uuid")]
InvalidLanguageUuid,
#[error("impossible memory requirement")]
ImpossibleMemoryRequirement,
}

impl From<ClientError> for Status {
fn from(value: ClientError) -> Self {
match value {
ClientError::InvaildSecret => Status::permission_denied("Invaild secret"),
ClientError::InvaildLanguageUuid => {
Status::failed_precondition("Invaild language uuid")
ClientError::InvalidSecret => Status::permission_denied("Invalid secret"),
ClientError::InvalidLanguageUuid => {
Status::failed_precondition("Invalid language uuid")
}
ClientError::ImpossibleMemoryRequirement => {
Status::failed_precondition("Impossible memory requirement")
Expand Down
12 changes: 6 additions & 6 deletions judger/src/filesystem/adapter/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ pub enum FuseError {
#[error("unimplemented")]
Unimplemented,
#[error("missed inode")]
InvaildIno,
InvalidIno,
#[error("missed handle")]
HandleNotFound,
#[error("underlaying file error")]
Underlaying,
#[error("underlying file error")]
Underlying,
#[error("invalid path")]
InvalidPath,
#[error("permission deny")]
PermissionDeny,
#[error("invalid argument")]
InvialdArg,
InvalidArg,
#[error("Already exist")]
AlreadyExist,
}
Expand All @@ -47,9 +47,9 @@ impl From<FuseError> for fuse3::Errno {
log::info!("out of resource");
libc::ENOMEM
}
FuseError::InvalidPath | FuseError::InvaildIno => libc::ENOENT,
FuseError::InvalidPath | FuseError::InvalidIno => libc::ENOENT,
FuseError::PermissionDeny => libc::EACCES,
FuseError::InvialdArg => libc::EINVAL,
FuseError::InvalidArg => libc::EINVAL,
FuseError::AlreadyExist => libc::EEXIST,
err => {
log::warn!("FUSE driver broken: {}", err);
Expand Down
27 changes: 13 additions & 14 deletions judger/src/filesystem/adapter/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{ffi::OsStr, num::NonZeroU32, path::Path, sync::Arc};
use bytes::Bytes;
use futures_core::Future;
use spin::Mutex;
use tokio::fs::metadata;
use tokio::io::{AsyncRead, AsyncSeek};
use tokio::sync::Mutex as AsyncMutex;

Expand Down Expand Up @@ -87,7 +86,7 @@ where

async fn lookup(&self, req: Request, parent: u64, name: &OsStr) -> FuseResult<ReplyEntry> {
let tree = self.tree.lock();
let parent_node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?;
let parent_node = tree.get(parent as usize).ok_or(FuseError::InvalidIno)?;
let node = parent_node
.get_by_component(name)
.ok_or(FuseError::InvalidPath)?;
Expand Down Expand Up @@ -122,7 +121,7 @@ where
}
async fn opendir(&self, _: Request, inode: u64, flags: u32) -> FuseResult<ReplyOpen> {
let tree = self.tree.lock();
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?;
if node.get_value().kind() != FileType::Directory {
return Err(FuseError::NotDir.into());
}
Expand All @@ -135,7 +134,7 @@ where
// ignore write permission, because some application may open files
// with write permission but never write
let tree = self.tree.lock();
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?;
if node.get_value().kind() == FileType::Directory {
return Err(FuseError::IsDir.into());
}
Expand All @@ -152,7 +151,7 @@ where
offset: i64,
) -> FuseResult<ReplyDirectory<Self::DirEntryStream<'_>>> {
let tree = self.tree.lock();
let node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(parent as usize).ok_or(FuseError::InvalidIno)?;

if node.get_value().kind() != FileType::Directory {
return Err(FuseError::NotDir.into());
Expand Down Expand Up @@ -201,7 +200,7 @@ where
_: u64,
) -> FuseResult<ReplyDirectoryPlus<Self::DirEntryPlusStream<'_>>> {
let tree = self.tree.lock();
let node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(parent as usize).ok_or(FuseError::InvalidIno)?;

if node.get_value().kind() != FileType::Directory {
return Err(FuseError::NotDir.into());
Expand Down Expand Up @@ -322,7 +321,7 @@ where
_: u32,
) -> FuseResult<()> {
let tree = self.tree.lock();
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?;

match node.get_value().kind() {
FileType::Directory | FileType::NamedPipe | FileType::CharDevice => {
Expand All @@ -342,7 +341,7 @@ where
_: u32,
) -> FuseResult<ReplyAttr> {
let tree = self.tree.lock();
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?;
// FIXME: unsure about the inode
Ok(reply_attr(&req, node.get_value(), inode))
}
Expand All @@ -354,7 +353,7 @@ where
_: SetAttr,
) -> FuseResult<ReplyAttr> {
let tree = self.tree.lock();
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?;
Ok(reply_attr(&req, node.get_value(), inode))
}
async fn create(
Expand All @@ -366,7 +365,7 @@ where
flags: u32,
) -> FuseResult<ReplyCreated> {
let mut tree = self.tree.lock();
let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvaildIno)?;
let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvalidIno)?;
if parent_node.get_value().kind() != FileType::Directory {
return Err(FuseError::NotDir.into());
}
Expand All @@ -389,7 +388,7 @@ where
_: u32,
) -> FuseResult<ReplyEntry> {
let mut tree = self.tree.lock();
let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvaildIno)?;
let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvalidIno)?;
if parent_node.get_value().kind() != FileType::Directory {
return Err(FuseError::NotDir.into());
}
Expand All @@ -401,18 +400,18 @@ where
}
async fn readlink(&self, _: Request, inode: Inode) -> FuseResult<ReplyData> {
let tree = self.tree.lock();
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(inode as usize).ok_or(FuseError::InvalidIno)?;
let link = node
.get_value()
.get_symlink()
.ok_or(FuseError::InvialdArg)?;
.ok_or(FuseError::InvalidArg)?;
Ok(ReplyData {
data: Bytes::copy_from_slice(link.as_encoded_bytes()),
})
}
async fn unlink(&self, _: Request, parent: Inode, name: &OsStr) -> FuseResult<()> {
let mut tree = self.tree.lock();
let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvaildIno)?;
let mut parent_node = tree.get_mut(parent as usize).ok_or(FuseError::InvalidIno)?;
if parent_node.get_value().kind() != FileType::Directory {
return Err(FuseError::NotDir.into());
}
Expand Down
2 changes: 1 addition & 1 deletion judger/src/filesystem/adapter/reply.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! collection of function that fill the value of
//! collection of function that fill with the value of
//! reply packets back to fuse connection
use std::{ffi::OsString, time::Duration};

Expand Down
2 changes: 1 addition & 1 deletion judger/src/filesystem/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +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;
resource.comsume_other(required_size.saturating_sub(self.get_size()))?;
resource.consume_other(required_size.saturating_sub(self.get_size()))?;

match self {
Self::MemFile(block) => Some(block.write(offset, data).await.unwrap()),
Expand Down
4 changes: 2 additions & 2 deletions judger/src/filesystem/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Filesystem module that is mountable(actuallly mount and
//! is accessible for user in this operation system)
//! Filesystem module that is mountable(actually mount and
//! is accessible for user in this operating system)
mod adapter;
mod entry;
mod handle;
Expand Down
6 changes: 3 additions & 3 deletions judger/src/filesystem/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Resource {
Self(AtomicU64::new(cap))
}
/// consume some amount of resource
pub fn comsume(&self, size: u32) -> Option<()> {
pub fn consume(&self, size: u32) -> Option<()> {
let a = self.0.fetch_sub(size as u64, Ordering::AcqRel);
if (a & (1 << 63)) != 0 {
None
Expand All @@ -23,8 +23,8 @@ impl Resource {
///
/// return None if the resource is not enough or the size
/// is out of range (greater than[`u32::MAX`])
pub fn comsume_other<T: TryInto<u32>>(&self, size: T) -> Option<()> {
pub fn consume_other<T: TryInto<u32>>(&self, size: T) -> Option<()> {
let size = size.try_into().ok()?;
self.comsume(size)
self.consume(size)
}
}
6 changes: 3 additions & 3 deletions judger/src/filesystem/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ mod test {
use super::*;
#[test]
fn test_adj_table() {
let mut table = super::AdjTable::new();
let mut table = AdjTable::new();
let mut root = table.insert_root(0);
root.insert(OsStr::new("a").into(), 1);
let mut b = root.insert(OsStr::new("b").into(), 2).unwrap();
Expand All @@ -306,7 +306,7 @@ mod test {
}
#[test]
fn get_or_insert() {
let mut table = super::AdjTable::new();
let mut table = AdjTable::new();
table.insert_root(0);
table.insert_by_path(
vec!["abc", "efg", "123", "456"]
Expand All @@ -325,7 +325,7 @@ mod test {
}
#[test]
fn parent_child_insert() {
let mut table = super::AdjTable::new();
let mut table = AdjTable::new();
let mut root = table.insert_root(0); // inode 1
assert_eq!(root.get_id(), 1);
let mut a = root.insert(OsStr::new("a").into(), 1).unwrap(); // inode 2
Expand Down
2 changes: 1 addition & 1 deletion judger/src/language/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Spec {
let mut raw: Raw = toml::from_str(content).unwrap();
raw.fill();

// FIXME: use compsition instead
// FIXME: use composition instead
Self {
info: LangInfo::from(&raw),
id: raw.id,
Expand Down
2 changes: 1 addition & 1 deletion judger/src/language/stage/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Judger {
}
}
}
AssertionMode::SkipContinousSpace => {
AssertionMode::SkipContinuousSpace => {
// skip space and newline, continous space is consider same
let output = output.iter().map(|x| match x {
b'\n' | b' ' => b' ',
Expand Down
10 changes: 5 additions & 5 deletions judger/src/language/stage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use run::Runner;

/// internal status code, use to decouple the grpc status code
///
/// Status code is commonly use in OJ, it include example such as: AC, WA...
/// Status code is commonly use in OJ, it includes example such as: AC, WA...
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum StatusCode {
Accepted,
Expand All @@ -27,7 +27,7 @@ pub enum StatusCode {

/// internal assertion mode, use to decouple the grpc status code
///
/// Assertion mode reperesent how the output is compared
/// Assertion mode represent how the output is compared
#[derive(Clone, Copy)]
pub enum AssertionMode {
/// Skip single space and newline
Expand All @@ -36,10 +36,10 @@ pub enum AssertionMode {
///
/// `a\nb` and `a\n\nb` are different
SkipSpace,
/// Skip continous space and newline
/// Skip continuous space and newline
///
/// `ab`, `a\nb` and `a\n\nb` are the same
SkipContinousSpace,
SkipContinuousSpace,
/// Exact match
Exact,
}
Expand All @@ -56,7 +56,7 @@ impl From<JudgeMatchRule> for AssertionMode {
match rule {
JudgeMatchRule::ExactSame => AssertionMode::Exact,
JudgeMatchRule::IgnoreSnl => AssertionMode::SkipSpace,
JudgeMatchRule::SkipSnl => AssertionMode::SkipContinousSpace,
JudgeMatchRule::SkipSnl => AssertionMode::SkipContinuousSpace,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion judger/src/language/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Runner {
/// See [`Context`] for more information
struct RunCtx {
spec: Arc<Spec>,
path: std::path::PathBuf,
path: PathBuf,
limit: Stat,
}

Expand Down
2 changes: 1 addition & 1 deletion judger/src/sandbox/monitor/mem_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl super::Monitor for Monitor {
/// get the final resource usage
///
/// Please remember thatActively limit(notify) cpu resource is achieved
/// by polling the cgroup, therefore the delay requirespecial attention,
/// by polling the cgroup, therefore the delay require special attention,
/// it is only guaranteed to below limitation provided + [`MONITOR_ACCURACY`].
async fn stat(self) -> Self::Resource {
// FIXME: check running process, this line is commented out because of uncollected process
Expand Down
6 changes: 3 additions & 3 deletions judger/src/sandbox/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ lazy_static::lazy_static! {

pub trait Monitor {
type Resource;
/// wait for exhuast of resource
/// wait for exhaust of resource
///
/// This function is cancel safe.
async fn wait_exhaust(&mut self) -> MonitorKind {
Expand All @@ -37,9 +37,9 @@ pub trait Monitor {
tokio::time::sleep(Duration::from_millis(12)).await;
}
}
/// poll for exhuast of resource
/// poll for exhaust of resource
///
/// Implementor should do bith [`wait_exhaust`] and [`poll_exhaust`]
/// Implementor should do both [`wait_exhaust`] and [`poll_exhaust`]
/// for better performance.
fn poll_exhaust(&mut self) -> Option<MonitorKind>;
/// get the resource usage
Expand Down
2 changes: 1 addition & 1 deletion judger/src/sandbox/monitor/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod test {

#[tokio::test]
async fn monitor_output_limit() {
let (mut stdin, stdout) = tokio::io::duplex(1024);
let (mut stdin, stdout) = duplex(1024);
let mut monitor = Monitor::inner_new(9, stdout);
stdin.write_all(b"1234567890").await.unwrap();
assert_eq!(
Expand Down
6 changes: 3 additions & 3 deletions judger/src/sandbox/monitor/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ impl<'a> CgroupWrapper<'a> {
/// get memory usage(statistics)
pub fn memory(&self) -> Memory {
let controller = self.0.controller_of::<MemController>().unwrap();
let kusage = controller.kmem_stat();
let kernel_usage = controller.kmem_stat();

let kernel = kusage.max_usage_in_bytes;
let kernel = kernel_usage.max_usage_in_bytes;
let user = controller.memory_stat().max_usage_in_bytes;
let total = kernel + user;

Expand Down Expand Up @@ -96,7 +96,7 @@ impl CgroupWrapperOwned {
}
/// poll until cgroup is deleted
///
/// After the cgroup is empty(`tasks` is empty), the cgroup is can be delete safely
/// After the cgroup is empty(`tasks` is empty), the cgroup is can be deleted safely
///
/// However, in some rare cases, the monitor is reading file in cgroup
/// when the cgroup is about to be deleted, this will cause the cgroup to stay busy
Expand Down
Loading

0 comments on commit 40c6a83

Please sign in to comment.