@@ -11,12 +11,7 @@ use tracing_subscriber::{fmt::format::FmtSpan, util::SubscriberInitExt};
11
11
// use lading_payload::block;
12
12
use nix:: libc:: { self , ENOENT } ;
13
13
use serde:: Deserialize ;
14
- use std:: {
15
- ffi:: OsStr ,
16
- num:: NonZeroU32 ,
17
- path:: PathBuf ,
18
- time:: { Duration , UNIX_EPOCH } ,
19
- } ;
14
+ use std:: { ffi:: OsStr , num:: NonZeroU32 , path:: PathBuf , time:: Duration } ;
20
15
21
16
// fn default_config_path() -> String {
22
17
// "/etc/lading/logrotate_fs.yaml".to_string()
@@ -83,6 +78,7 @@ const TTL: Duration = Duration::from_secs(1); // Attribute cache timeout
83
78
struct LogrotateFS {
84
79
state : model:: State ,
85
80
start_time : std:: time:: Instant ,
81
+ start_time_system : std:: time:: SystemTime ,
86
82
}
87
83
88
84
impl LogrotateFS {
@@ -95,33 +91,46 @@ impl LogrotateFS {
95
91
fn getattr_helper ( & mut self , tick : model:: Tick , inode : usize ) -> Option < FileAttr > {
96
92
let nlink = self . state . nlink ( inode) as u32 ;
97
93
98
- self . state . getattr ( tick, inode) . map ( |attr| FileAttr {
99
- ino : attr. inode as u64 ,
100
- size : attr. size ,
101
- blocks : ( attr. size + 511 ) / 512 ,
102
- // TODO these times should reflect those in the model, will need to
103
- // be translated from the tick to systemtime. Implies we'll need to
104
- // adjust up from start_time, knowing that a tick is one second
105
- // wide.
106
- atime : UNIX_EPOCH ,
107
- mtime : UNIX_EPOCH ,
108
- ctime : UNIX_EPOCH ,
109
- crtime : UNIX_EPOCH ,
110
- kind : match attr. kind {
111
- model:: NodeType :: File => fuser:: FileType :: RegularFile ,
112
- model:: NodeType :: Directory => fuser:: FileType :: Directory ,
113
- } ,
114
- perm : if matches ! ( attr. kind, model:: NodeType :: Directory ) {
115
- 0o755
116
- } else {
117
- 0o644
118
- } ,
119
- nlink,
120
- uid : unsafe { libc:: getuid ( ) } ,
121
- gid : unsafe { libc:: getgid ( ) } ,
122
- rdev : 0 ,
123
- blksize : 512 ,
124
- flags : 0 ,
94
+ self . state . getattr ( tick, inode) . map ( |attr| {
95
+ // Convert ticks to durations
96
+ let access_duration = Duration :: from_secs ( attr. access_tick ) ;
97
+ let modified_duration = Duration :: from_secs ( attr. modified_tick ) ;
98
+ let status_duration = Duration :: from_secs ( attr. status_tick ) ;
99
+
100
+ // Calculate SystemTime instances
101
+ let atime = self . start_time_system + access_duration;
102
+ let mtime = self . start_time_system + modified_duration;
103
+ let ctime = self . start_time_system + status_duration;
104
+ let crtime = self . start_time_system ; // Assume creation time is when the filesystem started
105
+
106
+ FileAttr {
107
+ ino : attr. inode as u64 ,
108
+ size : attr. size ,
109
+ blocks : ( attr. size + 511 ) / 512 ,
110
+ // TODO these times should reflect those in the model, will need to
111
+ // be translated from the tick to systemtime. Implies we'll need to
112
+ // adjust up from start_time, knowing that a tick is one second
113
+ // wide.
114
+ atime,
115
+ mtime,
116
+ ctime,
117
+ crtime,
118
+ kind : match attr. kind {
119
+ model:: NodeType :: File => fuser:: FileType :: RegularFile ,
120
+ model:: NodeType :: Directory => fuser:: FileType :: Directory ,
121
+ } ,
122
+ perm : if matches ! ( attr. kind, model:: NodeType :: Directory ) {
123
+ 0o755
124
+ } else {
125
+ 0o644
126
+ } ,
127
+ nlink,
128
+ uid : unsafe { libc:: getuid ( ) } ,
129
+ gid : unsafe { libc:: getgid ( ) } ,
130
+ rdev : 0 ,
131
+ blksize : 512 ,
132
+ flags : 0 ,
133
+ }
125
134
} )
126
135
}
127
136
}
@@ -297,6 +306,7 @@ fn main() -> Result<(), Error> {
297
306
let fs = LogrotateFS {
298
307
state,
299
308
start_time : std:: time:: Instant :: now ( ) ,
309
+ start_time_system : std:: time:: SystemTime :: now ( ) ,
300
310
} ;
301
311
302
312
// Mount the filesystem
0 commit comments