Skip to main content

endpoint_sec/event/
event_file_provider_materialize.rs

1//! [`EventFileProviderMaterialize`]
2
3use endpoint_sec_sys::es_event_file_provider_materialize_t;
4
5use crate::{AuditToken, File, Process};
6
7/// Materialize a file via the FileProvider framework event.
8#[doc(alias = "es_event_file_provider_materialize_t")]
9pub struct EventFileProviderMaterialize<'a> {
10    /// The raw reference.
11    pub(crate) raw: &'a es_event_file_provider_materialize_t,
12
13    /// The version of the message.
14    pub(crate) version: u32,
15}
16
17impl<'a> EventFileProviderMaterialize<'a> {
18    /// The process that instigated the materialization.
19    #[inline(always)]
20    pub fn instigator(&self) -> Option<Process<'a>> {
21        // Safety: 'a tied to self, object obtained through ES
22        let process = unsafe { self.raw.instigator()? };
23        Some(Process::new(process, self.version))
24    }
25
26    /// Audit token of the process that instigated this event.
27    pub fn instigator_token(&self) -> AuditToken {
28        #[cfg(feature = "macos_15_0_0")]
29        if self.version >= 8 {
30            return AuditToken(self.raw.instigator_token)
31        }
32
33        // On old versions, the process was always non-null, and we can get
34        // its token easily.
35        self.instigator().unwrap().audit_token()
36    }
37
38    /// The staged file that has been materialized
39    #[inline(always)]
40    pub fn source(&self) -> File<'a> {
41        // Safety: 'a tied to self, object obtained through ES
42        File::new(unsafe { self.raw.source() })
43    }
44
45    /// The destination of the staged source file.
46    #[inline(always)]
47    pub fn target(&self) -> File<'a> {
48        // Safety: 'a tied to self, object obtained through ES
49        File::new(unsafe { self.raw.target() })
50    }
51}
52
53// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
54unsafe impl Send for EventFileProviderMaterialize<'_> {}
55// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
56unsafe impl Sync for EventFileProviderMaterialize<'_> {}
57
58impl_debug_eq_hash_with_functions!(EventFileProviderMaterialize<'a> with version; instigator, instigator_token, source, target);