in ospatch/zypper_patch.go [100:183]
func RunZypperPatch(ctx context.Context, opts ...ZypperPatchOption) error {
zOpts := &zypperPatchOpts{
excludes: nil,
exclusivePatches: nil,
categories: nil,
severities: nil,
withOptional: false,
withUpdate: false,
}
for _, opt := range opts {
opt(zOpts)
}
zListOpts := []packages.ZypperListOption{
packages.ZypperListPatchCategories(zOpts.categories),
packages.ZypperListPatchSeverities(zOpts.severities),
packages.ZypperListPatchWithOptional(zOpts.withOptional),
// if there is no filter on category and severity,
// zypper fetches all available patch updates
}
patches, err := packages.ZypperPatches(ctx, zListOpts...)
if err != nil {
return err
}
// if user specifies, --with-update get the necessary patch/package
// information and then runfilter on them
var pkgToPatchesMap map[string][]string
var pkgUpdates []*packages.PkgInfo
if zOpts.withUpdate {
pkgUpdates, err = packages.ZypperUpdates(ctx)
if err != nil {
return err
}
pkgToPatchesMap, err = packages.ZypperPackagesInPatch(ctx, patches)
if err != nil {
return err
}
}
fPatches, fpkgs, err := runFilter(patches, zOpts.exclusivePatches, zOpts.excludes, pkgUpdates, pkgToPatchesMap, zOpts.withUpdate)
if len(fPatches) == 0 && len(fpkgs) == 0 {
clog.Infof(ctx, "No updates required.")
return nil
}
var ops opsToReport
if len(fPatches) == 0 {
clog.Infof(ctx, "No patches to install.")
} else {
msg := fmt.Sprintf("%d patches: %s", len(fPatches), formatPatches(fPatches))
if zOpts.dryrun {
clog.Infof(ctx, "Running in dryrun mode, not installing %s", msg)
} else {
ops.patches = fPatches
}
}
if len(fpkgs) == 0 {
clog.Infof(ctx, "No non-patch packages to update.")
} else {
msg := fmt.Sprintf("%d patches: %q", len(fpkgs), fpkgs)
if zOpts.dryrun {
clog.Infof(ctx, "Running in dryrun mode, not Updating %s", msg)
} else {
ops.packages = fpkgs
}
}
logOps(ctx, ops)
if zOpts.dryrun {
return nil
}
err = packages.ZypperInstall(ctx, fPatches, fpkgs)
if err == nil {
logSuccess(ctx, ops)
} else {
logFailure(ctx, ops, err)
}
return err
}