in agentendpoint/patch_windows.go [58:105]
func (r *patchTask) installWUAUpdates(ctx context.Context, cf []string) (int32, error) {
clog.Infof(ctx, "Searching for available Windows updates.")
session, err := packages.NewUpdateSession()
if err != nil {
return 0, err
}
defer session.Close()
updts, err := ospatch.GetWUAUpdates(ctx, session, cf, r.Task.GetPatchConfig().GetWindowsUpdate().GetExcludes(), r.Task.GetPatchConfig().GetWindowsUpdate().GetExclusivePatches())
if err != nil {
return 0, err
}
defer updts.Release()
count, err := updts.Count()
if err != nil {
return 0, err
}
if count == 0 {
clog.Infof(ctx, "No Windows updates available to install")
return 0, nil
}
clog.Infof(ctx, "%d Windows updates to install", count)
if r.Task.GetDryRun() {
clog.Infof(ctx, "Running in dryrun mode, not updating.")
return 0, nil
}
for i := int32(0); i < count; i++ {
if err := r.reportContinuingState(ctx, agentendpointpb.ApplyPatchesTaskProgress_APPLYING_PATCHES); err != nil {
return i, err
}
updt, err := updts.Item(int(i))
if err != nil {
return i, err
}
defer updt.Release()
if err := session.InstallWUAUpdate(ctx, updt); err != nil {
return i, fmt.Errorf(`installUpdate(updt): %v`, err)
}
}
return count, nil
}