Skip to content

Commit

Permalink
Ensure file size updates due to getattr
Browse files Browse the repository at this point in the history
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 <brian.troutwine@datadoghq.com>
  • Loading branch information
blt committed Oct 24, 2024
1 parent b66b30d commit 8c02a22
Showing 1 changed file with 30 additions and 17 deletions.
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

0 comments on commit 8c02a22

Please sign in to comment.