Fix code quality: trailing whitespace, unused imports, clippy warnings

- Fix trailing whitespace in kex.rs and s3.rs
- Add missing KexProposal import in kex_complete.rs
- Auto-fix clippy warnings across all crates
- All 153 tests pass
This commit is contained in:
Warren
2026-06-19 05:21:38 +08:00
parent 4b37e524cf
commit d94cb2df4c
135 changed files with 7256 additions and 4321 deletions

View File

@@ -6,6 +6,12 @@ pub struct ThreadSafeCache {
path_cache: Mutex<HashMap<String, String>>, // path -> node_id
}
impl Default for ThreadSafeCache {
fn default() -> Self {
Self::new()
}
}
impl ThreadSafeCache {
pub fn new() -> Self {
Self {

View File

@@ -44,7 +44,9 @@ impl DbManager {
let mut stmt = conn.prepare(sql)?;
let result = if level == 0 {
stmt.query_row(params![component, &self.tree_type], |row| row.get::<_, String>(0))
stmt.query_row(params![component, &self.tree_type], |row| {
row.get::<_, String>(0)
})
} else {
stmt.query_row(
params![component, &self.tree_type, current_parent.as_ref().unwrap()],
@@ -79,7 +81,8 @@ impl DbManager {
pub fn get_node_info(&self, node_id: &str) -> Result<Option<(String, u64)>> {
let conn = self.conn.lock().unwrap();
let sql = "SELECT node_type, file_size FROM file_nodes WHERE node_id = ?1 AND tree_type = ?2";
let sql =
"SELECT node_type, file_size FROM file_nodes WHERE node_id = ?1 AND tree_type = ?2";
let mut stmt = conn.prepare(sql)?;
let result = stmt.query_row(params![node_id, &self.tree_type], |row| {
@@ -100,7 +103,9 @@ impl DbManager {
let mut stmt = conn.prepare(sql)?;
let labels = stmt
.query_map(params![parent_id, &self.tree_type], |row| row.get::<_, String>(0))?
.query_map(params![parent_id, &self.tree_type], |row| {
row.get::<_, String>(0)
})?
.collect::<Result<Vec<_>, _>>()?;
Ok(labels)
@@ -112,7 +117,9 @@ impl DbManager {
let sql = "SELECT node_id FROM file_nodes WHERE parent_id = ?1 AND label = ?2 AND tree_type = ?3 LIMIT 1";
let mut stmt = conn.prepare(sql)?;
let result = stmt.query_row(params![parent_id, name, &self.tree_type], |row| row.get::<_, String>(0));
let result = stmt.query_row(params![parent_id, name, &self.tree_type], |row| {
row.get::<_, String>(0)
});
match result {
Ok(node_id) => Ok(Some(node_id)),

View File

@@ -1,10 +1,10 @@
use anyhow::Result;
use fuse_backend_rs::api::filesystem::{Context, DirEntry, Entry, FileSystem, ZeroCopyWriter};
use fuse_backend_rs::abi::fuse_abi::{stat64, statvfs64, FsOptions, OpenOptions};
use fuse_backend_rs::api::filesystem::{Context, DirEntry, Entry, FileSystem, ZeroCopyWriter};
use std::collections::HashMap;
use std::ffi::CStr;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom};
use std::io::Read;
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::sync::{Arc, RwLock};
use std::time::{Duration, SystemTime};
@@ -51,7 +51,7 @@ impl MarkBaseFs {
let mut next = self.next_inode.write().unwrap();
let ino = *next;
*next += 1;
let mut map = self.inode_map.write().unwrap();
map.insert(ino, node_id.to_string());
ino
@@ -65,14 +65,17 @@ impl MarkBaseFs {
st.st_uid = 501;
st.st_gid = 20;
st.st_size = file_size as i64;
st.st_blocks = ((file_size + 511) / 512) as i64;
st.st_blocks = file_size.div_ceil(512) as i64;
st.st_blksize = 4096;
let now = SystemTime::now();
st.st_atime = now.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as i64;
st.st_atime = now
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs() as i64;
st.st_mtime = st.st_atime;
st.st_ctime = st.st_atime;
st
}
}
@@ -85,20 +88,22 @@ impl FileSystem for MarkBaseFs {
Ok(capable)
}
fn lookup(
&self,
ctx: &Context,
parent: Self::Inode,
name: &CStr,
) -> std::io::Result<Entry> {
fn lookup(&self, _ctx: &Context, parent: Self::Inode, name: &CStr) -> std::io::Result<Entry> {
let name_str = name.to_string_lossy();
let node_id = if parent == 1 {
self.db.find_node_id(&format!("/{}", name_str)).ok().flatten()
self.db
.find_node_id(&format!("/{}", name_str))
.ok()
.flatten()
} else {
let parent_id = self.find_node_id_by_inode(parent);
match parent_id {
Some(pid) => self.db.find_node_id_by_parent(&pid, &name_str).ok().flatten(),
Some(pid) => self
.db
.find_node_id_by_parent(&pid, &name_str)
.ok()
.flatten(),
None => None,
}
};
@@ -127,16 +132,16 @@ impl FileSystem for MarkBaseFs {
}
}
fn forget(&self, ctx: &Context, inode: Self::Inode, count: u64) {
fn forget(&self, _ctx: &Context, inode: Self::Inode, _count: u64) {
let mut map = self.inode_map.write().unwrap();
map.remove(&inode);
}
fn getattr(
&self,
ctx: &Context,
_ctx: &Context,
inode: Self::Inode,
handle: Option<Self::Handle>,
_handle: Option<Self::Handle>,
) -> std::io::Result<(stat64, Duration)> {
if inode == 1 {
let attr = MarkBaseFs::make_stat64("folder", 0);
@@ -161,24 +166,24 @@ impl FileSystem for MarkBaseFs {
fn open(
&self,
ctx: &Context,
_ctx: &Context,
inode: Self::Inode,
flags: u32,
fuse_flags: u32,
_flags: u32,
_fuse_flags: u32,
) -> std::io::Result<(Option<Self::Handle>, OpenOptions, Option<u32>)> {
Ok((Some(inode), OpenOptions::empty(), None))
}
fn read(
&self,
ctx: &Context,
_ctx: &Context,
inode: Self::Inode,
handle: Self::Handle,
_handle: Self::Handle,
w: &mut dyn ZeroCopyWriter,
size: u32,
offset: u64,
lock_owner: Option<u64>,
flags: u32,
_lock_owner: Option<u64>,
_flags: u32,
) -> std::io::Result<usize> {
let node_id = self.find_node_id_by_inode(inode);
match node_id {
@@ -190,7 +195,7 @@ impl FileSystem for MarkBaseFs {
let fd = file.as_raw_fd();
let f = unsafe { File::from_raw_fd(fd) };
let mut f = std::mem::ManuallyDrop::new(f);
w.write_from(&mut *f, size as usize, offset)
}
_ => Err(std::io::Error::from_raw_os_error(libc::ENOENT)),
@@ -202,32 +207,32 @@ impl FileSystem for MarkBaseFs {
fn release(
&self,
ctx: &Context,
inode: Self::Inode,
flags: u32,
handle: Self::Handle,
flush: bool,
flock_release: bool,
lock_owner: Option<u64>,
_ctx: &Context,
_inode: Self::Inode,
_flags: u32,
_handle: Self::Handle,
_flush: bool,
_flock_release: bool,
_lock_owner: Option<u64>,
) -> std::io::Result<()> {
Ok(())
}
fn opendir(
&self,
ctx: &Context,
_ctx: &Context,
inode: Self::Inode,
flags: u32,
_flags: u32,
) -> std::io::Result<(Option<Self::Handle>, OpenOptions)> {
Ok((Some(inode), OpenOptions::empty()))
}
fn readdir(
&self,
ctx: &Context,
_ctx: &Context,
inode: Self::Inode,
handle: Self::Handle,
size: u32,
_handle: Self::Handle,
_size: u32,
offset: u64,
add_entry: &mut dyn FnMut(DirEntry) -> std::io::Result<usize>,
) -> std::io::Result<()> {
@@ -252,19 +257,15 @@ impl FileSystem for MarkBaseFs {
fn releasedir(
&self,
ctx: &Context,
inode: Self::Inode,
flags: u32,
handle: Self::Handle,
_ctx: &Context,
_inode: Self::Inode,
_flags: u32,
_handle: Self::Handle,
) -> std::io::Result<()> {
Ok(())
}
fn statfs(
&self,
ctx: &Context,
inode: Self::Inode,
) -> std::io::Result<statvfs64> {
fn statfs(&self, _ctx: &Context, _inode: Self::Inode) -> std::io::Result<statvfs64> {
let mut st = unsafe { std::mem::zeroed::<statvfs64>() };
st.f_bsize = 4096;
st.f_blocks = 1000000;
@@ -276,4 +277,4 @@ impl FileSystem for MarkBaseFs {
st.f_namemax = 255;
Ok(st)
}
}
}

View File

@@ -30,7 +30,11 @@ fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Mount { user, dir, tree_type } => {
Commands::Mount {
user,
dir,
tree_type,
} => {
mount_user(user, tree_type, dir)?;
}
Commands::Unmount { dir } => {
@@ -78,13 +82,15 @@ fn mount_user(user: String, tree_type: String, dir: PathBuf) -> Result<()> {
println!("Press Ctrl+C to unmount...");
let mut channel = session.new_channel()?;
let ebadf = std::io::Error::from_raw_os_error(libc::EBADF);
loop {
if let Some((reader, writer)) = channel.get_request()? {
if let Err(e) = server.handle_message(reader, writer.into(), None, None) {
match e {
fuse_backend_rs::Error::EncodeMessage(e) if e.kind() == std::io::ErrorKind::Other => {
fuse_backend_rs::Error::EncodeMessage(e)
if e.kind() == std::io::ErrorKind::Other =>
{
break;
}
_ => {
@@ -112,4 +118,4 @@ fn unmount_user(dir: PathBuf) -> Result<()> {
println!("Unmounted successfully");
Ok(())
}
}