Skip to content

Commit 082ca8b

Browse files
sozercanashnamehrotra
authored andcommitted
fix: handle mariner zstd compression (project-copacetic#295)
1 parent e9cba83 commit 082ca8b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pkg/pkgmgr/rpm.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535
rpmManifest2 = "container-manifest-2"
3636
rpmManifestWildcard = "container-manifest-*"
3737

38-
installToolsCmd = "yum install busybox -y"
38+
installToolsCmd = "yum install busybox cpio -y"
3939
resultQueryFormat = "%{NAME}\t%{VERSION}-%{RELEASE}\t%{ARCH}\n"
4040
)
4141

@@ -359,17 +359,16 @@ func (rm *rpmManager) unpackAndMergeUpdates(ctx context.Context, updates types.U
359359
// - Reports being slightly out of date, where a newer security revision has displaced the one specified leading to not found errors.
360360
// - Reports not specifying version epochs correct (e.g. bsdutils=2.36.1-8+deb11u1 instead of with epoch as 1:2.36.1-8+dev11u1)
361361
// - Reports specifying remediation packages for cbl-mariner v1 instead of v2 (e.g. *.cm1.aarch64 instead of *.cm2.aarch64)
362-
const aptDownloadTemplate = "yum reinstall --downloadonly --downloaddir=. --best -y %s"
362+
const rpmDownloadTemplate = `yum reinstall --downloadonly --downloaddir=. --best -y %s`
363363
pkgStrings := []string{}
364364
for _, u := range updates {
365365
pkgStrings = append(pkgStrings, u.Name)
366366
}
367-
downloadCmd := fmt.Sprintf(aptDownloadTemplate, strings.Join(pkgStrings, " "))
367+
downloadCmd := fmt.Sprintf(rpmDownloadTemplate, strings.Join(pkgStrings, " "))
368368
downloaded := busyboxCopied.Run(llb.Shlex(downloadCmd), llb.WithProxy(utils.GetProxy())).Root()
369369

370370
// Scripted enumeration and rpm install of all downloaded packages under the download folder as root
371-
// `rpm -i` doesn't support installing to a target directory, so chroot into the download folder to install the packages.
372-
const extractTemplate = `chroot %s ./busybox find . -name '*.rpm' -exec ./busybox rpm -i '{}' \;`
371+
const extractTemplate = `sh -c 'for f in %[1]s/*.rpm ; do rpm2cpio "$f" | cpio -idmv -D %[1]s ; done'`
373372
extractCmd := fmt.Sprintf(extractTemplate, downloadPath)
374373
unpacked := downloaded.Run(llb.Shlex(extractCmd)).Root()
375374

0 commit comments

Comments
 (0)