use crate::ClusterId;
use crate::PathBuf;
use crate::api::raw_directory_entry::Attributes;
use crate::api::timestamp::VfatTimestamp;
use alloc::string::String;
#[derive(Debug, Clone)]
pub struct Metadata {
creation: VfatTimestamp,
last_update: VfatTimestamp,
pub(crate) name: String,
pub(crate) size: u32,
path: PathBuf,
pub(crate) cluster: ClusterId,
parent: PathBuf,
pub(crate) attributes: Attributes,
}
impl Metadata {
pub(crate) fn new<S: AsRef<str>>(
creation: VfatTimestamp,
last_update: VfatTimestamp,
name: S,
size: u32,
path: PathBuf,
cluster: ClusterId,
parent: PathBuf,
attributes: Attributes,
) -> Self {
Self {
creation,
last_update,
name: String::from(name.as_ref()),
size,
path,
cluster,
parent,
attributes,
}
}
}
impl Metadata {
pub fn size(&self) -> usize {
self.size as usize
}
pub(crate) fn last_update(&self) -> Option<VfatTimestamp> {
Some(self.last_update)
}
pub(crate) fn creation(&self) -> Option<VfatTimestamp> {
Some(self.creation)
}
pub fn full_path(&self) -> &PathBuf {
&self.path
}
pub(crate) fn parent(&self) -> &PathBuf {
&self.parent
}
pub fn name(&self) -> &str {
&self.name
}
pub(crate) fn has_no_cluster_allocated(&self) -> bool {
self.cluster == ClusterId::new(0)
}
}