Skip to content

Commit 7217520

Browse files
committed
add a File::new to tidy up more
Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent bf07a6d commit 7217520

File tree

1 file changed

+34
-36
lines changed
  • lading/src/generator/file_gen/logrotate_fs

1 file changed

+34
-36
lines changed

lading/src/generator/file_gen/logrotate_fs/model.rs

+34-36
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,35 @@ impl FileHandle {
9999
}
100100

101101
impl File {
102+
/// Create a new instance of `File`
103+
pub(crate) fn new(
104+
parent: Inode,
105+
bytes_per_tick: u64,
106+
group_id: u16,
107+
now: Tick,
108+
peer: Option<Inode>,
109+
) -> Self {
110+
Self {
111+
parent,
112+
bytes_written: 0,
113+
bytes_read: 0,
114+
access_tick: now,
115+
modified_tick: now,
116+
status_tick: now,
117+
created_tick: now,
118+
bytes_per_tick,
119+
read_only: false,
120+
read_only_since: None,
121+
ordinal: 0,
122+
peer,
123+
group_id,
124+
open_handles: 0,
125+
unlinked: false,
126+
max_offset_observed: 0,
127+
}
128+
}
129+
102130
/// Open a new handle to this file.
103-
///
104-
/// TODO these need to modify access time et al
105131
pub(crate) fn open(&mut self, now: Tick) {
106132
self.advance_time(now);
107133
if now > self.access_tick {
@@ -440,24 +466,7 @@ impl State {
440466
let file_inode = state.next_inode;
441467
state.next_inode += 1;
442468

443-
let file = File {
444-
parent: current_inode,
445-
bytes_written: 0,
446-
bytes_read: 0,
447-
access_tick: state.now,
448-
modified_tick: state.now,
449-
status_tick: state.now,
450-
created_tick: state.now,
451-
bytes_per_tick,
452-
read_only: false,
453-
ordinal: 0,
454-
peer: None,
455-
group_id,
456-
open_handles: 0,
457-
unlinked: false,
458-
max_offset_observed: 0,
459-
read_only_since: None,
460-
};
469+
let file = File::new(current_inode, bytes_per_tick, group_id, state.now, None);
461470
state.nodes.insert(file_inode, Node::File { file });
462471

463472
// Add the file to the directory's children
@@ -564,24 +573,13 @@ impl State {
564573
// become the 0th ordinal in the `group_id` and may -- although
565574
// we don't know yet -- cause `rotated_inode` to be deleted.
566575
let new_file_inode = self.next_inode;
567-
let mut new_file = File {
568-
parent: parent_inode,
569-
bytes_written: 0,
570-
bytes_read: 0,
571-
access_tick: self.now,
572-
modified_tick: self.now,
573-
status_tick: self.now,
574-
created_tick: self.now,
576+
let mut new_file = File::new(
577+
parent_inode,
575578
bytes_per_tick,
576-
read_only: false,
577-
ordinal: 0,
578-
peer: Some(rotated_inode),
579579
group_id,
580-
open_handles: 0,
581-
unlinked: false,
582-
max_offset_observed: 0,
583-
read_only_since: None,
584-
};
580+
self.now,
581+
Some(rotated_inode),
582+
);
585583
new_file.advance_time(now);
586584
self.next_inode = self.next_inode.saturating_add(1);
587585

0 commit comments

Comments
 (0)