From b6b6c8c9ffe6bc3fa44fec937488e3e38b220800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Virtus?= Date: Wed, 17 May 2023 14:12:59 +0200 Subject: [PATCH] Allow same globs in multiple slices There's no reason why the following slices shouldn't be accepted when the globs are identical: package: openjdk-8-jre-headless slices: abc: contents: /usr/lib/jvm/java-8-openjdk-*/jre/lib/*/libnpt.so: bcd: contents: /usr/lib/jvm/java-8-openjdk-*/jre/lib/*/libnpt.so: Drop this restriction. --- internal/deb/extract.go | 6 ++++-- internal/deb/extract_test.go | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/deb/extract.go b/internal/deb/extract.go index 1eb8908d..702c5513 100644 --- a/internal/deb/extract.go +++ b/internal/deb/extract.go @@ -38,8 +38,10 @@ func checkExtractOptions(options *ExtractOptions) error { for extractPath, extractInfos := range options.Extract { isGlob := strings.ContainsAny(extractPath, "*?") if isGlob { - if len(extractInfos) != 1 || extractInfos[0].Path != extractPath || extractInfos[0].Mode != 0 { - return fmt.Errorf("when using wildcards source and target paths must match: %s", extractPath) + for _, info := range extractInfos { + if info.Path != extractPath || info.Mode != 0 { + return fmt.Errorf("when using wildcards source and target paths must match: %s", extractPath) + } } } } diff --git a/internal/deb/extract_test.go b/internal/deb/extract_test.go index 9cc79df9..c55da47f 100644 --- a/internal/deb/extract_test.go +++ b/internal/deb/extract_test.go @@ -170,7 +170,7 @@ var extractTests = []extractTest{{ }, error: `cannot extract .*: when using wildcards source and target paths must match: /etc/d\*\*`, }, { - summary: "Globbing must also have a single target", + summary: "Two slices can declare the same glob", pkgdata: testutil.PackageData["base-files"], options: deb.ExtractOptions{ Extract: map[string][]deb.ExtractInfo{ @@ -181,7 +181,25 @@ var extractTests = []extractTest{{ }}, }, }, - error: `cannot extract .*: when using wildcards source and target paths must match: /etc/d\*\*`, + result: map[string]string{ + "/etc/": "dir 0755", + "/etc/debian_version": "file 0644 cce26cfe", + "/etc/default/": "dir 0755", + "/etc/dpkg/": "dir 0755", + "/etc/dpkg/origins/": "dir 0755", + "/etc/dpkg/origins/debian": "file 0644 50f35af8", + "/etc/dpkg/origins/ubuntu": "file 0644 d2537b95", + }, + globbed: map[string][]string{ + "/etc/d**": []string{ + "/etc/debian_version", + "/etc/default/", + "/etc/dpkg/", + "/etc/dpkg/origins/", + "/etc/dpkg/origins/debian", + "/etc/dpkg/origins/ubuntu", + }, + }, }, { summary: "Globbing cannot change modes", pkgdata: testutil.PackageData["base-files"],