From 3e1421e353afcc494263100d52836f63ea66d914 Mon Sep 17 00:00:00 2001 From: lczyk Date: Sat, 10 Oct 2026 03:16:13 +0100 Subject: [PATCH] fix: explicit path entries hidden by implicit parent directories addKnownPath registered the parents of a known path with empty data and never replaced them, so a directory first seen as the parent of an extracted file lost the "until: mutate" of its own explicit entry when that entry was processed later. Generated content is created after the extraction and iterates a map, so this happened every time for a made directory with an extracted child, and at random for a generated directory with a generated child. Implicit parents are now marked as such and an explicit entry replaces them. --- internal/slicer/slicer.go | 9 ++++++--- internal/slicer/slicer_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) 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"}},