MCPcopy Create free account
hub / github.com/PowerShell/DSC / handle_set

Function handle_set

resources/WindowsUpdate/src/windows_update/set.rs:20–303  ·  view source on GitHub ↗
(input: &str)

Source from the content-addressed store, hash-verified

18}
19
20pub fn handle_set(input: &str) -> Result<String> {
21 // Parse input as UpdateList
22 let update_list: UpdateList = serde_json::from_str(input)
23 .map_err(|e| Error::new(E_INVALIDARG, t!("set.failedParseInput", err = e.to_string())))?;
24
25 if update_list.updates.is_empty() {
26 return Err(Error::new(E_INVALIDARG, t!("set.updatesArrayEmpty")));
27 }
28
29 // Initialize COM
30 let com_initialized = unsafe {
31 CoInitializeEx(Some(std::ptr::null()), COINIT_MULTITHREADED).is_ok()
32 };
33
34 let result: Result<(Vec<UpdateInfo>, bool)> = unsafe {
35 // Create update session
36 let update_session: IUpdateSession = CoCreateInstance(
37 &UpdateSession,
38 None,
39 CLSCTX_INPROC_SERVER,
40 )?;
41
42 // Create update searcher
43 let searcher = update_session.CreateUpdateSearcher()?;
44
45 // Search for all updates (installed and not installed)
46 let search_result = searcher.Search(&BSTR::from("IsInstalled=0 or IsInstalled=1"))?;
47
48 // Get updates collection
49 let all_updates = search_result.Updates()?;
50 let count = all_updates.Count()?;
51
52 // First pass: Verify all input objects have matches
53 let mut matched_updates: Vec<(IUpdate, bool)> = Vec::new();
54
55 for update_input in &update_list.updates {
56 // Validate that at least one search criterion is provided
57 if update_input.title.is_none()
58 && update_input.id.is_none()
59 && update_input.kb_article_ids.is_none()
60 && update_input.is_installed.is_none()
61 && update_input.update_type.is_none()
62 && update_input.msrc_severity.is_none() {
63 return Err(Error::new(E_INVALIDARG, t!("set.atLeastOneCriterionRequired")));
64 }
65
66 // Find the update matching ALL provided criteria (logical AND)
67 let mut found_update: Option<(IUpdate, bool)> = None;
68 let mut matching_updates: Vec<(IUpdate, bool)> = Vec::new();
69 for i in 0..count {
70 let update = all_updates.get_Item(i)?;
71
72 // Check title match
73 if let Some(search_title) = &update_input.title {
74 let title = update.Title()?.to_string();
75 if !title.eq_ignore_ascii_case(search_title) {
76 continue; // Title doesn't match, skip this update
77 }

Callers 1

mainFunction · 0.50

Calls 8

extract_update_infoFunction · 0.85
as_strMethod · 0.80
get_computer_nameFunction · 0.70
from_strFunction · 0.50
newFunction · 0.50
to_stringFunction · 0.50
is_emptyMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected