memfs: take mtimes from tar

This commit is contained in:
2025-08-14 15:55:38 +03:00
parent 6469914be1
commit c1b62aef1d
2 changed files with 34 additions and 13 deletions
+33 -12
View File
@@ -20,6 +20,7 @@ use yggdrasil_abi::{
error::Error,
io::{FileMode, FileType, GroupId, UserId},
path::Path,
time::SystemTime,
};
use crate::tar::TarIterator;
@@ -75,6 +76,7 @@ impl<A: BlockAllocator> MemoryFilesystem<A> {
path: &Path,
create: bool,
mode: FileMode,
mtime: SystemTime,
) -> Result<NodeRef, Error> {
let access = unsafe { AccessToken::authorized() };
if path.is_empty() {
@@ -97,7 +99,18 @@ impl<A: BlockAllocator> MemoryFilesystem<A> {
}
let ino = INO_COUNTER.fetch_add(1, Ordering::Relaxed);
let node = DirectoryNode::<A>::new(self.clone(), Metadata::now_root(mode, ino));
let metadata = Metadata {
uid: UserId::root(),
gid: GroupId::root(),
atime: mtime,
ctime: mtime,
mode,
mtime,
inode: Some(ino),
block_size: 512,
block_count: 0,
};
let node = DirectoryNode::<A>::new(self.clone(), metadata);
at.add_child(filename, node.clone())?;
node
@@ -112,7 +125,7 @@ impl<A: BlockAllocator> MemoryFilesystem<A> {
Ok(node)
} else {
assert!(node.is_directory());
self.make_path(&node, rest, create, mode)
self.make_path(&node, rest, create, mode, mtime)
}
}
@@ -120,16 +133,22 @@ impl<A: BlockAllocator> MemoryFilesystem<A> {
let kind = hdr.node_kind();
let mode = usize::from(&hdr.mode);
let mode = FileMode::new(0o777 & (mode as u32));
let mtime = SystemTime::new(usize::from(&hdr.mtime) as u64, 0);
let ino = INO_COUNTER.fetch_add(1, Ordering::Relaxed);
let metadata = Metadata {
uid: UserId::root(),
gid: GroupId::root(),
atime: mtime,
ctime: mtime,
mode,
mtime,
inode: Some(ino),
block_size: 512,
block_count: usize::from(&hdr.size).div_ceil(512) as u64,
};
match kind {
FileType::File => Ok(FileNode::<A>::new(
self.clone(),
Metadata::now_root(mode, ino),
)),
FileType::Directory => Ok(DirectoryNode::<A>::new(
self.clone(),
Metadata::now_root(mode, ino),
)),
FileType::File => Ok(FileNode::<A>::new(self.clone(), metadata)),
FileType::Directory => Ok(DirectoryNode::<A>::new(self.clone(), metadata)),
FileType::Symlink => {
let target = hdr.symlink_target()?;
Ok(fixed_path_symlink(target))
@@ -149,9 +168,10 @@ impl<A: BlockAllocator> MemoryFilesystem<A> {
};
let path = Path::from_str(hdr.name.as_str()?.trim_matches('/'));
let mtime = SystemTime::new(usize::from(&hdr.mtime) as u64, 0);
let (dirname, filename) = path.split_right();
let parent = self.make_path(&root, dirname, true, FileMode::new(0o755))?;
let parent = self.make_path(&root, dirname, true, FileMode::new(0o755), mtime)?;
let node = self.create_node_initial(hdr)?;
let filename = Filename::new(filename)?;
@@ -164,8 +184,9 @@ impl<A: BlockAllocator> MemoryFilesystem<A> {
panic!("Unreachable");
};
let mtime = SystemTime::new(usize::from(&hdr.mtime) as u64, 0);
let path = Path::from_str(hdr.name.as_str()?.trim_matches('/'));
let node = self.make_path(&root, path, false, FileMode::empty())?;
let node = self.make_path(&root, path, false, FileMode::empty(), mtime)?;
assert_eq!(node.ty(), hdr.node_kind());
let uid = unsafe { UserId::from_raw(usize::from(&hdr.uid) as u32) };
+1 -1
View File
@@ -23,7 +23,7 @@ pub(crate) struct TarEntry {
pub uid: OctalField<8>,
pub gid: OctalField<8>,
pub size: OctalField<12>,
_mtime: OctalField<12>,
pub mtime: OctalField<12>,
_checksum: OctalField<8>,
type_: u8,
link_name: TarString<100>,