diff --git a/lib/vfs/src/host_fs.rs b/lib/vfs/src/host_fs.rs index 275ee27f0d6..19475768e51 100644 --- a/lib/vfs/src/host_fs.rs +++ b/lib/vfs/src/host_fs.rs @@ -422,7 +422,7 @@ impl VirtualFile for File { #[cfg(unix)] fn host_file_bytes_available(host_fd: FileDescriptor) -> Result { - let mut bytes_found = 0 as libc::c_int; + let mut bytes_found: libc::c_int = 0; let result = unsafe { libc::ioctl(host_fd.try_into()?, libc::FIONREAD, &mut bytes_found) }; match result { diff --git a/lib/vfs/src/lib.rs b/lib/vfs/src/lib.rs index bc554a505ab..50a80edbad5 100644 --- a/lib/vfs/src/lib.rs +++ b/lib/vfs/src/lib.rs @@ -355,6 +355,7 @@ impl DirEntry { } } +#[allow(clippy::len_without_is_empty)] // Clippy thinks it's an iterator. #[derive(Clone, Debug, Default)] // TODO: review this, proper solution would probably use a trait object internally pub struct Metadata { @@ -369,21 +370,27 @@ impl Metadata { pub fn is_file(&self) -> bool { self.ft.is_file() } + pub fn is_dir(&self) -> bool { self.ft.is_dir() } + pub fn accessed(&self) -> u64 { self.accessed } + pub fn created(&self) -> u64 { self.created } + pub fn modified(&self) -> u64 { self.modified } + pub fn file_type(&self) -> FileType { self.ft.clone() } + pub fn len(&self) -> u64 { self.len } diff --git a/lib/vfs/src/mem_fs/file.rs b/lib/vfs/src/mem_fs/file.rs index 9eeb07f2eac..fe0862ee000 100644 --- a/lib/vfs/src/mem_fs/file.rs +++ b/lib/vfs/src/mem_fs/file.rs @@ -94,7 +94,7 @@ impl VirtualFile for FileHandle { match fs.storage.get(self.inode) { Some(Node::File { file, .. }) => file.buffer.len().try_into().unwrap_or(0), - _ => return 0, + _ => 0, } } diff --git a/lib/vfs/src/mem_fs/filesystem.rs b/lib/vfs/src/mem_fs/filesystem.rs index 7c8d74247d1..9e2913ed7bc 100644 --- a/lib/vfs/src/mem_fs/filesystem.rs +++ b/lib/vfs/src/mem_fs/filesystem.rs @@ -394,7 +394,7 @@ impl FileSystemInner { _ => None, }) - .or_else(|| Some(None)) + .or(Some(None)) .ok_or(FsError::InvalidInput), _ => Err(FsError::BaseNotDirectory), @@ -519,12 +519,11 @@ impl FileSystemInner { impl fmt::Debug for FileSystemInner { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( + writeln!( formatter, - "\n{inode:<8} {ty:<4} {name}\n", + "\n{inode:<8} {ty:<4} name", inode = "inode", ty = "type", - name = "name", )?; fn debug( @@ -534,9 +533,9 @@ impl fmt::Debug for FileSystemInner { indentation: usize, ) -> fmt::Result { for node in nodes { - write!( + writeln!( formatter, - "{inode:<8} {ty:<4} {indentation_symbol:indentation_width$}{name}\n", + "{inode:<8} {ty:<4} {indentation_symbol:indentation_width$}{name}", inode = node.inode(), ty = match node { Node::File { .. } => "file",