Skip to content

Commit

Permalink
fix(Judger): 🐛 Fix lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed May 10, 2024
1 parent a84ba27 commit 6340782
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
24 changes: 12 additions & 12 deletions judger/src/filesystem/adapter/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ where
) -> impl Future<Output = FuseResult<ReplyEntry>> + Send {
async move {
let tree = self.tree.lock();
let node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?;
let entry = node.get_by_component(name).ok_or(FuseError::InvalidPath)?;
let parent_node = tree.get(parent as usize).ok_or(FuseError::InvaildIno)?;
let node = parent_node.get_by_component(name).ok_or(FuseError::InvalidPath)?;
// FIXME: unsure about the inode
Ok(reply_entry(&req, entry.get_value(), parent))
Ok(reply_entry(&req, node.get_value(), node.get_id() as u64))
}
}
fn forget(&self, _: Request, inode: u64, _: u64) -> impl Future<Output = ()> + Send {
Expand Down Expand Up @@ -134,13 +134,13 @@ where
) -> impl Future<Output = FuseResult<ReplyOpen>> + Send {
async move {
let tree = self.tree.lock();
let entry = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
if entry.get_value().kind() == FileType::Directory {
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
if node.get_value().kind() == FileType::Directory {
return Err(FuseError::IsDir.into());
}
let fh = self
.handle_table
.add(AsyncMutex::new(entry.get_value().clone()));
.add(AsyncMutex::new(node.get_value().clone()));
Ok(ReplyOpen { fh, flags: 0 })
}
}
Expand Down Expand Up @@ -262,8 +262,8 @@ where
size: u32,
) -> impl Future<Output = FuseResult<ReplyData>> + Send {
async move {
let entry = self.handle_table.get(fh).ok_or(FuseError::HandleNotFound)?;
let mut lock = entry.lock().await;
let session = self.handle_table.get(fh).ok_or(FuseError::HandleNotFound)?;
let mut lock = session.lock().await;
Ok(lock
.read(offset, size)
.await
Expand All @@ -282,13 +282,13 @@ where
flags: u32,
) -> impl Future<Output = FuseResult<ReplyWrite>> + Send {
async move {
let entry = self
let session = self
.handle_table
.get(fh)
.ok_or(FuseError::HandleNotFound)
.unwrap();

Ok(Entry::write(entry, offset, data, &self.resource)
Ok(Entry::write(session, offset, data, &self.resource)
.await
.ok_or_else(|| Into::<Errno>::into(FuseError::IsDir))?
.map(|written| ReplyWrite { written })?)
Expand Down Expand Up @@ -354,9 +354,9 @@ where
) -> impl Future<Output = FuseResult<ReplyAttr>> + Send {
async move {
let tree = self.tree.lock();
let entry = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
let node = tree.get(inode as usize).ok_or(FuseError::InvaildIno)?;
// FIXME: unsure about the inode
Ok(reply_attr(&req, entry.get_value(), inode))
Ok(reply_attr(&req, node.get_value(), inode))
}
}
fn setattr(
Expand Down
4 changes: 2 additions & 2 deletions judger/src/filesystem/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod test {
.try_init()
.ok();

log::info!("mounting test tarball in .temp/1 ...");
log::info!("mounting test tarball in .temp ...");
let global_resource = Semaphore::new(4096 * 1024 * 1024, 1);
let template = Template::new("test/nested.tar").await.unwrap();
let filesystem = template
Expand All @@ -32,7 +32,7 @@ mod test {
.unwrap(),
)
.await;
let mut mount_handle = filesystem.mount("./.temp/11").await.unwrap();
let mut mount_handle = filesystem.mount("./.temp/18").await.unwrap();
let handle = &mut mount_handle;

tokio::select! {
Expand Down
6 changes: 2 additions & 4 deletions judger/src/filesystem/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::{
sync::{Mutex, OwnedMutexGuard},
};

use super::{table::DeepClone, resource::Resource};
use super::{resource::Resource, table::DeepClone};

pub const MEMBLOCK_BLOCKSIZE: usize = 4096;

Expand Down Expand Up @@ -109,9 +109,7 @@ where
}
match &mut *lock {
Self::MemFile(block) => Some(block.write(offset, data).await),
Self::TarFile(block) => {
todo!()
}
Self::TarFile(block) => Some(Err(std::io::Error::from(std::io::ErrorKind::Other))),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion judger/src/filesystem/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Filesystem module that is mountable(actuall mount and
//! is accessible for user in this operation system)
mod adapter;
mod table;
mod entry;
mod error;
mod resource;
mod table;

pub use entry::prelude::*;
2 changes: 1 addition & 1 deletion judger/src/filesystem/table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::{BTreeMap},
collections::BTreeMap,
ffi::{OsStr, OsString},
path::{Component, Path},
};
Expand Down

0 comments on commit 6340782

Please sign in to comment.