Replace lexical Rust fragments with real modules

This commit is contained in:
ms2k 2026-07-19 05:12:57 +09:00
commit 247819250b

View file

@ -1,5 +1,12 @@
use super::{
Classification, ClassificationSnapshot, Duration, Errno, File, FileType, FlockOperation,
HashMap, INodeNo, IgnoredWorkspace, LockFlags, Mode, OFlags, OsStr, OsStrExt, OsString,
OsStringExt, Path, PathBuf, ReplyEmpty, ReplyXattr, SystemTime, TimeOrNow, Timespec,
UNIX_EPOCH, UTIME_NOW, UTIME_OMIT, io, tracked_paths_from_index,
};
impl IgnoredWorkspace {
fn remove(&self, parent: INodeNo, name: &OsStr, directory: bool, reply: ReplyEmpty) {
pub(super) fn remove(&self, parent: INodeNo, name: &OsStr, directory: bool, reply: ReplyEmpty) {
let result = (|| {
let path = self.child_path(parent, name)?;
let snapshot = self.classifier.snapshot_for(&path);
@ -9,7 +16,7 @@ impl IgnoredWorkspace {
reply_result(result, reply);
}
fn with_temporary_file<T>(
pub(super) fn with_temporary_file<T>(
&self,
inode: INodeNo,
operation: impl FnOnce(&File) -> io::Result<T>,
@ -23,7 +30,7 @@ impl IgnoredWorkspace {
operation(&file)
}
fn require_index_publication_safe(
pub(super) fn require_index_publication_safe(
&self,
backing: Classification,
source: &Path,
@ -50,46 +57,46 @@ impl IgnoredWorkspace {
}
}
struct ResolvedEntry {
path: PathBuf,
backing: Classification,
stat: rustix::fs::Stat,
pub(super) struct ResolvedEntry {
pub(super) path: PathBuf,
pub(super) backing: Classification,
pub(super) stat: rustix::fs::Stat,
}
struct OpenFile {
file: File,
backing: Classification,
access_mode: i32,
pub(super) struct OpenFile {
pub(super) file: File,
pub(super) backing: Classification,
pub(super) access_mode: i32,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct PosixLockKey {
backing: Classification,
device: u64,
inode: u64,
owner: u64,
pub(super) struct PosixLockKey {
pub(super) backing: Classification,
pub(super) device: u64,
pub(super) inode: u64,
pub(super) owner: u64,
}
struct DirectoryStream {
directory: File,
entries: Vec<DirectoryEntry>,
_snapshot: ClassificationSnapshot,
pub(super) struct DirectoryStream {
pub(super) directory: File,
pub(super) entries: Vec<DirectoryEntry>,
pub(super) _snapshot: ClassificationSnapshot,
}
struct DirectoryEntry {
inode: INodeNo,
kind: FileType,
name: OsString,
pub(super) struct DirectoryEntry {
pub(super) inode: INodeNo,
pub(super) kind: FileType,
pub(super) name: OsString,
}
struct NodeTable {
pub(super) struct NodeTable {
paths: HashMap<u64, PathBuf>,
inodes: HashMap<NodeKey, u64>,
next_inode: u64,
}
impl NodeTable {
fn new() -> Self {
pub(super) fn new() -> Self {
Self {
paths: HashMap::from([(INodeNo::ROOT.0, PathBuf::new())]),
inodes: HashMap::new(),
@ -97,11 +104,11 @@ impl NodeTable {
}
}
fn path(&self, inode: INodeNo) -> Option<PathBuf> {
pub(super) fn path(&self, inode: INodeNo) -> Option<PathBuf> {
self.paths.get(&inode.0).cloned()
}
fn inode(&mut self, entry: &ResolvedEntry) -> INodeNo {
pub(super) fn inode(&mut self, entry: &ResolvedEntry) -> INodeNo {
let key = NodeKey {
path: entry.path.clone(),
backing: entry.backing,
@ -127,13 +134,13 @@ struct NodeKey {
inode: u64,
}
fn open_flags(flags: i32) -> OFlags {
pub(super) fn open_flags(flags: i32) -> OFlags {
let mut result = OFlags::from_bits_retain(u32::from_ne_bytes(flags.to_ne_bytes()));
result.remove(OFlags::CREATE | OFlags::EXCL | OFlags::NOFOLLOW | OFlags::CLOEXEC);
result
}
fn file_type(mode: u32) -> io::Result<FileType> {
pub(super) fn file_type(mode: u32) -> io::Result<FileType> {
match mode & libc::S_IFMT {
libc::S_IFREG => Ok(FileType::RegularFile),
libc::S_IFDIR => Ok(FileType::Directory),
@ -146,7 +153,7 @@ fn file_type(mode: u32) -> io::Result<FileType> {
}
}
fn system_time(seconds: i64, nanoseconds: u64) -> SystemTime {
pub(super) fn system_time(seconds: i64, nanoseconds: u64) -> SystemTime {
if seconds >= 0 {
UNIX_EPOCH
+ Duration::new(
@ -158,7 +165,7 @@ fn system_time(seconds: i64, nanoseconds: u64) -> SystemTime {
}
}
fn timestamp(value: Option<TimeOrNow>) -> Timespec {
pub(super) fn timestamp(value: Option<TimeOrNow>) -> Timespec {
match value {
Some(TimeOrNow::Now) => Timespec {
tv_sec: 0,
@ -178,18 +185,18 @@ fn timestamp(value: Option<TimeOrNow>) -> Timespec {
}
}
fn writable_xattr(name: &OsStr) -> bool {
pub(super) fn writable_xattr(name: &OsStr) -> bool {
matches!(
name.as_bytes(),
b"system.posix_acl_access" | b"system.posix_acl_default"
) || name.as_bytes().starts_with(b"user.")
}
fn unsupported_lock_flags(flags: LockFlags) -> bool {
pub(super) fn unsupported_lock_flags(flags: LockFlags) -> bool {
flags.bits() & !LockFlags::FUSE_LK_FLOCK.bits() != 0
}
fn bsd_lock_operation(typ: i32, sleep: bool) -> io::Result<FlockOperation> {
pub(super) fn bsd_lock_operation(typ: i32, sleep: bool) -> io::Result<FlockOperation> {
match (typ, sleep) {
(libc::F_RDLCK, true) => Ok(FlockOperation::LockShared),
(libc::F_RDLCK, false) => Ok(FlockOperation::NonBlockingLockShared),
@ -201,7 +208,7 @@ fn bsd_lock_operation(typ: i32, sleep: bool) -> io::Result<FlockOperation> {
}
}
fn record_lock(start: u64, end: u64, typ: i32) -> io::Result<libc::flock> {
pub(super) fn record_lock(start: u64, end: u64, typ: i32) -> io::Result<libc::flock> {
if start > end {
return Err(io::Error::from_raw_os_error(libc::EINVAL));
}
@ -235,7 +242,7 @@ fn record_lock(start: u64, end: u64, typ: i32) -> io::Result<libc::flock> {
})
}
fn fuse_lock(lock: &libc::flock) -> io::Result<(u64, u64, i32, u32)> {
pub(super) fn fuse_lock(lock: &libc::flock) -> io::Result<(u64, u64, i32, u32)> {
let start =
u64::try_from(lock.l_start).map_err(|_| io::Error::from_raw_os_error(libc::EOVERFLOW))?;
let end = if lock.l_len == 0 {
@ -255,18 +262,18 @@ fn fuse_lock(lock: &libc::flock) -> io::Result<(u64, u64, i32, u32)> {
))
}
fn errno(error: &io::Error) -> Errno {
pub(super) fn errno(error: &io::Error) -> Errno {
Errno::from_i32(error.raw_os_error().unwrap_or(libc::EIO))
}
fn reply_result(result: io::Result<()>, reply: ReplyEmpty) {
pub(super) fn reply_result(result: io::Result<()>, reply: ReplyEmpty) {
match result {
Ok(()) => reply.ok(),
Err(error) => reply.error(errno(&error)),
}
}
fn reply_xattr(result: io::Result<Vec<u8>>, size: u32, reply: ReplyXattr) {
pub(super) fn reply_xattr(result: io::Result<Vec<u8>>, size: u32, reply: ReplyXattr) {
match result {
Ok(bytes) if size == 0 => reply.size(u32::try_from(bytes.len()).unwrap_or(u32::MAX)),
Ok(bytes) if bytes.len() <= size as usize => reply.data(&bytes),
@ -274,4 +281,3 @@ fn reply_xattr(result: io::Result<Vec<u8>>, size: u32, reply: ReplyXattr) {
Err(error) => reply.error(errno(&error)),
}
}