Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure file size updates due to getattr #1042

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions lading/src/generator/file_gen/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -299,23 +309,26 @@ impl State {
pub fn getattr(&mut self, now: Tick, inode: Inode) -> Option<NodeAttributes> {
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,
},
}
})
}

Expand Down
Loading