Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ impl TryFrom<&libc::stat> for FileAttr {
ino: NodeID::from_raw(st.st_ino).ok_or(TryIntoFileAttrError::InvalidNodeID)?,
size: transmute!(st.st_size),
mode: FileMode::from_raw(st.st_mode),
nlink: st.st_nlink.try_into()?,
nlink: (st.st_nlink as u64).try_into()?,
uid: Uid::from_raw(st.st_uid),
gid: Gid::from_raw(st.st_gid),
rdev: DeviceID::from_userspace_dev(st.st_rdev),
blksize: st.st_blksize.try_into()?,
blksize: (st.st_blksize as u64).try_into()?,
Comment on lines +422 to +426
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using (st.st_nlink as u64).try_into()? / (st.st_blksize as u64).try_into()? works around the Infallible error-type mismatch on platforms where the source field is already u32, but it does so by forcing an as cast. A more direct (and easier to reason about) fix is to make TryIntoFileAttrError convertible from std::convert::Infallible (e.g., via a From<Infallible> impl that is unreachable), or explicitly handle the Infallible case when calling try_into(). That would allow keeping the original try_into()? without widening casts and keeps the intent clearer across architectures.

Copilot uses AI. Check for mistakes.
blocks: transmute!(st.st_blocks),
atime: Duration::new(transmute!(st.st_atime), st.st_atime_nsec as _),
mtime: Duration::new(transmute!(st.st_mtime), st.st_mtime_nsec as _),
Expand All @@ -449,11 +449,11 @@ impl TryFrom<&Metadata> for FileAttr {
ino: NodeID::from_raw(m.ino()).ok_or(TryIntoFileAttrError::InvalidNodeID)?,
size: m.size(),
mode: FileMode::from_raw(m.mode()),
nlink: m.nlink().try_into()?,
nlink: (m.nlink() as u64).try_into()?,
uid: Uid::from_raw(m.uid()),
gid: Gid::from_raw(m.gid()),
rdev: DeviceID::from_userspace_dev(m.rdev()),
blksize: m.blksize().try_into()?,
blksize: (m.blksize() as u64).try_into()?,
Comment on lines +452 to +456
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MetadataExt::nlink() and MetadataExt::blksize() are already u64 on Unix, so the added as u64 casts are redundant here and slightly obscure that the only potentially-failing step is the u64 -> u32 narrowing conversion. Consider dropping the cast (and if you add a From<Infallible> for TryIntoFileAttrError as suggested above, the libc::stat and Metadata conversions can stay consistent).

Copilot uses AI. Check for mistakes.
blocks: m.blocks(),
atime: Duration::new(transmute!(m.atime()), m.atime_nsec() as _),
mtime: Duration::new(transmute!(m.mtime()), m.mtime_nsec() as _),
Expand Down
Loading