use super::fs::FileFlags;
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use std::io::Result;
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use std::time::SystemTime;
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
pub struct Permissions {
read_only: bool,
}
impl Permissions {
pub fn readonly(&self) -> bool {
self.read_only
}
pub fn set_readonly(&mut self, readonly: bool) {
self.read_only = readonly;
}
}
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub(crate) struct FileTime {
created: SystemTime,
accessed: SystemTime,
modified: SystemTime,
}
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
impl Default for FileTime {
fn default() -> Self {
Self {
created: SystemTime::now(),
accessed: SystemTime::now(),
modified: SystemTime::now(),
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct FileType(FileFlags);
impl FileType {
pub fn is_dir(&self) -> bool {
self.0.contains(FileFlags::DIR)
}
pub fn is_file(&self) -> bool {
self.0.contains(FileFlags::FILE)
}
pub fn is_symlink(&self) -> bool {
self.0.contains(FileFlags::SYM_LINK)
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Metadata {
permissions: Permissions,
flags: FileFlags,
length: u64,
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
time: FileTime,
}
impl Metadata {
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub(crate) fn new(
permissions: Permissions,
flags: FileFlags,
length: u64,
time: FileTime,
) -> Self {
Self {
permissions,
flags,
length,
time,
}
}
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub(crate) fn new(
permissions: Permissions,
flags: FileFlags,
length: u64,
) -> Self {
Self {
permissions,
flags,
length,
}
}
pub fn file_type(&self) -> FileType {
FileType(self.flags)
}
pub fn is_dir(&self) -> bool {
self.file_type().is_dir()
}
pub fn is_file(&self) -> bool {
self.file_type().is_file()
}
pub fn is_symlink(&self) -> bool {
self.file_type().is_symlink()
}
pub fn len(&self) -> u64 {
self.length
}
pub fn permissions(&self) -> Permissions {
self.permissions
}
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub fn accessed(&self) -> Result<SystemTime> {
Ok(self.time.accessed)
}
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub fn created(&self) -> Result<SystemTime> {
Ok(self.time.created)
}
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub fn modified(&self) -> Result<SystemTime> {
Ok(self.time.modified)
}
}