From 340087fb52173896040682f7cc51e6947e6cac3f Mon Sep 17 00:00:00 2001 From: "Brian L. Troutwine" Date: Wed, 16 Oct 2024 16:40:44 -0700 Subject: [PATCH] Ensure file size updates due to getattr This commit ensures that a Node has advance_time called on it when the filesystem calls getattr. If this is not done repeat calls to ls, for instance, will show the file size not changing although a call to read would. Signed-off-by: Brian L. Troutwine --- lading/src/generator/file_gen/model.rs | 47 ++++++++++++++++---------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/lading/src/generator/file_gen/model.rs b/lading/src/generator/file_gen/model.rs index c65dc8071..5649014aa 100644 --- a/lading/src/generator/file_gen/model.rs +++ b/lading/src/generator/file_gen/model.rs @@ -146,6 +146,16 @@ pub enum Node { }, } +impl Node { + /// Run the clock forward on this node + pub fn advance_time(&mut self, now: Tick) { + match self { + Node::Directory { .. } => { /* nothing, intentionally */ } + Node::File { file, .. } => file.advance_time(now), + } + } +} + /// The state of the filesystem /// /// This structure is responsible for maintenance of the structure of the @@ -299,23 +309,26 @@ impl State { pub fn getattr(&mut self, now: Tick, inode: Inode) -> Option { self.advance_time(now); - self.nodes.get(&inode).map(|node| match node { - Node::File { file, .. } => NodeAttributes { - inode, - kind: NodeType::File, - size: file.bytes_written, - access_tick: file.access_tick, - modified_tick: file.modified_tick, - status_tick: file.status_tick, - }, - Node::Directory { .. } => NodeAttributes { - inode, - kind: NodeType::Directory, - size: 0, - access_tick: self.now, - modified_tick: self.now, - status_tick: self.now, - }, + self.nodes.get_mut(&inode).map(|node| { + node.advance_time(now); + match node { + Node::File { file, .. } => NodeAttributes { + inode, + kind: NodeType::File, + size: file.bytes_written, + access_tick: file.access_tick, + modified_tick: file.modified_tick, + status_tick: file.status_tick, + }, + Node::Directory { .. } => NodeAttributes { + inode, + kind: NodeType::Directory, + size: 0, + access_tick: self.now, + modified_tick: self.now, + status_tick: self.now, + }, + } }) }