1use std::path::PathBuf;
2use std::time::SystemTime;
3
4use remotefs::fs::{FileType, Metadata, UnixPex};
5
6#[derive(Debug, Clone)]
8pub struct Inode {
9 pub(crate) metadata: Metadata,
11 pub(crate) content: Option<Vec<u8>>,
13}
14
15impl Inode {
16 pub fn dir(uid: u32, gid: u32, mode: UnixPex) -> Self {
18 Self {
19 metadata: Metadata::default()
20 .uid(uid)
21 .gid(gid)
22 .file_type(FileType::Directory)
23 .created(SystemTime::now())
24 .accessed(SystemTime::now())
25 .mode(mode),
26 content: None,
27 }
28 }
29
30 pub fn file(uid: u32, gid: u32, mode: UnixPex, data: Vec<u8>) -> Self {
32 Self {
33 metadata: Metadata::default()
34 .uid(uid)
35 .gid(gid)
36 .file_type(FileType::File)
37 .created(SystemTime::now())
38 .accessed(SystemTime::now())
39 .mode(mode)
40 .size(data.len() as u64),
41 content: Some(data),
42 }
43 }
44
45 pub fn symlink(uid: u32, gid: u32, target: PathBuf) -> Self {
47 Self {
48 metadata: Metadata::default()
49 .uid(uid)
50 .gid(gid)
51 .file_type(FileType::Symlink)
52 .created(SystemTime::now())
53 .accessed(SystemTime::now())
54 .mode(UnixPex::from(0o777))
55 .symlink(target.clone()),
56 content: Some(target.to_string_lossy().as_bytes().to_vec()),
57 }
58 }
59
60 pub fn metadata(&self) -> &Metadata {
62 &self.metadata
63 }
64
65 pub fn content(&self) -> Option<&[u8]> {
67 self.content.as_deref()
68 }
69}