endpoint_sec/event/event_utimes.rs
1//! [`EventUTimes`]
2
3use std::time::SystemTime;
4
5use endpoint_sec_sys::es_event_utimes_t;
6
7use crate::{utils, File};
8
9/// Change file access and modification times (e.g. via utimes(2))
10#[doc(alias = "es_event_utimes_t")]
11pub struct EventUTimes<'a> {
12 /// Raw event
13 pub(crate) raw: &'a es_event_utimes_t,
14}
15
16impl<'a> EventUTimes<'a> {
17 /// The path which will have its times modified.
18 #[inline(always)]
19 pub fn target(&self) -> File<'a> {
20 // Safety: 'a tied to self, object obtained through ES
21 File::new(unsafe { self.raw.target() })
22 }
23
24 /// The desired new access time, in its raw form.
25 ///
26 /// See also [`Self::atime()`]
27 #[inline(always)]
28 pub fn raw_atime(&self) -> endpoint_sec_sys::timespec {
29 self.raw.atime
30 }
31
32 /// The desired new access time.
33 ///
34 /// See also [`Self::raw_atime()`]
35 #[inline(always)]
36 pub fn atime(&self) -> SystemTime {
37 let dur = utils::convert_timespec_to_duration(self.raw.atime);
38 SystemTime::UNIX_EPOCH + dur
39 }
40
41 /// The desired new modification time, in its raw form.
42 ///
43 /// See also [`Self::mtime()`]
44 #[inline(always)]
45 pub fn raw_mtime(&self) -> endpoint_sec_sys::timespec {
46 self.raw.mtime
47 }
48
49 /// The desired new modification time.
50 ///
51 /// See also [`Self::raw_mtime()`]
52 #[inline(always)]
53 pub fn mtime(&self) -> SystemTime {
54 let dur = utils::convert_timespec_to_duration(self.raw.mtime);
55 SystemTime::UNIX_EPOCH + dur
56 }
57}
58
59// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
60unsafe impl Send for EventUTimes<'_> {}
61// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
62unsafe impl Sync for EventUTimes<'_> {}
63
64impl_debug_eq_hash_with_functions!(EventUTimes<'a>; target, atime, mtime);