Skip to content

Commit 8c02a22

Browse files
committed
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 <[email protected]>
1 parent b66b30d commit 8c02a22

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

lading/src/generator/file_gen/model.rs

+30-17
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ pub enum Node {
146146
},
147147
}
148148

149+
impl Node {
150+
/// Run the clock forward on this node
151+
pub fn advance_time(&mut self, now: Tick) {
152+
match self {
153+
Node::Directory { .. } => { /* nothing, intentionally */ }
154+
Node::File { file, .. } => file.advance_time(now),
155+
}
156+
}
157+
}
158+
149159
/// The state of the filesystem
150160
///
151161
/// This structure is responsible for maintenance of the structure of the
@@ -299,23 +309,26 @@ impl State {
299309
pub fn getattr(&mut self, now: Tick, inode: Inode) -> Option<NodeAttributes> {
300310
self.advance_time(now);
301311

302-
self.nodes.get(&inode).map(|node| match node {
303-
Node::File { file, .. } => NodeAttributes {
304-
inode,
305-
kind: NodeType::File,
306-
size: file.bytes_written,
307-
access_tick: file.access_tick,
308-
modified_tick: file.modified_tick,
309-
status_tick: file.status_tick,
310-
},
311-
Node::Directory { .. } => NodeAttributes {
312-
inode,
313-
kind: NodeType::Directory,
314-
size: 0,
315-
access_tick: self.now,
316-
modified_tick: self.now,
317-
status_tick: self.now,
318-
},
312+
self.nodes.get_mut(&inode).map(|node| {
313+
node.advance_time(now);
314+
match node {
315+
Node::File { file, .. } => NodeAttributes {
316+
inode,
317+
kind: NodeType::File,
318+
size: file.bytes_written,
319+
access_tick: file.access_tick,
320+
modified_tick: file.modified_tick,
321+
status_tick: file.status_tick,
322+
},
323+
Node::Directory { .. } => NodeAttributes {
324+
inode,
325+
kind: NodeType::Directory,
326+
size: 0,
327+
access_tick: self.now,
328+
modified_tick: self.now,
329+
status_tick: self.now,
330+
},
331+
}
319332
})
320333
}
321334

0 commit comments

Comments
 (0)