diff --git a/internal/slicer/slicer.go b/internal/slicer/slicer.go index ce791162..bb297ef7 100644 --- a/internal/slicer/slicer.go +++ b/internal/slicer/slicer.go @@ -35,6 +35,9 @@ type pathData struct { until setup.PathUntil mutable bool hardLink bool + // implicit is set when the path is only known as the parent of another + // known path and no slice has listed it yet. + implicit bool } type contentChecker struct { @@ -439,12 +442,12 @@ func addKnownPath(knownPaths map[string]pathData, path string, data pathData) { slashPath += "/" } for { - if _, ok := knownPaths[slashPath]; ok { + if old, ok := knownPaths[slashPath]; ok && !old.implicit { break } knownPaths[slashPath] = data - // The parents have empty data. - data = pathData{} + // The parents have empty data until a slice lists them explicitly. + data = pathData{implicit: true} cleanPath = filepath.Dir(cleanPath) if cleanPath == "/" { break diff --git a/internal/slicer/slicer_test.go b/internal/slicer/slicer_test.go index d6ef9ca0..182b144a 100644 --- a/internal/slicer/slicer_test.go +++ b/internal/slicer/slicer_test.go @@ -517,6 +517,38 @@ var slicerTests = []slicerTest{{ manifestPaths: map[string]string{ "/dir/nested/file-copy": "file 0644 cc55e2ec {test-package_myslice}", }, +}, { + summary: "Script: 'until' on a made directory that is also an implicit parent", + slices: []setup.SliceKey{{"test-package", "myslice"}}, + release: map[string]string{ + "slices/mydir/test-package.yaml": ` + package: test-package + slices: + myslice: + contents: + /dir/: {make: true, until: mutate} + /dir/file: {until: mutate} + `, + }, + // Extracting /dir/file registers /dir/ as an implicit parent before the + // generated content is created, which must not hide the explicit entry. + filesystem: map[string]string{}, + manifestPaths: map[string]string{}, +}, { + summary: "Script: 'until' on a generated directory and its generated child", + slices: []setup.SliceKey{{"test-package", "myslice"}}, + release: map[string]string{ + "slices/mydir/test-package.yaml": ` + package: test-package + slices: + myslice: + contents: + /gen/: {make: true, until: mutate} + /gen/text: {text: data1, until: mutate} + `, + }, + filesystem: map[string]string{}, + manifestPaths: map[string]string{}, }, { summary: "Script: writing same contents to existing file does not set the final hash in report", slices: []setup.SliceKey{{"test-package", "myslice"}},