mirror of
https://github.com/moby/buildkit.git
synced 2026-08-04 23:00:51 +00:00
executor: stubs cleaner should remove empty directory mounts
On Linux, an empty directory is usually 4096 bytes, not 0, so we need an additional explicit check here. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@@ -185,6 +185,7 @@ func TestIntegration(t *testing.T) {
|
||||
testSBOMScan,
|
||||
testSBOMScanSingleRef,
|
||||
testMultipleCacheExports,
|
||||
testMountStubsDirectory,
|
||||
testMountStubsTimestamp,
|
||||
)
|
||||
}
|
||||
@@ -8106,6 +8107,52 @@ func testMultipleCacheExports(t *testing.T, sb integration.Sandbox) {
|
||||
ensureFileContents(t, filepath.Join(destDir, "unique"), string(uniqueFile))
|
||||
}
|
||||
|
||||
func testMountStubsDirectory(t *testing.T, sb integration.Sandbox) {
|
||||
c, err := New(sb.Context(), sb.Address())
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
st := llb.Image("busybox:latest").Run(
|
||||
llb.Args([]string{"/bin/echo", "dummy"}),
|
||||
llb.AddMount("/foo/bar", llb.Scratch(), llb.Tmpfs()),
|
||||
)
|
||||
def, err := st.Marshal(sb.Context())
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpDir := t.TempDir()
|
||||
tarFile := filepath.Join(tmpDir, "out.tar")
|
||||
tarFileW, err := os.Create(tarFile)
|
||||
require.NoError(t, err)
|
||||
defer tarFileW.Close()
|
||||
|
||||
_, err = c.Solve(sb.Context(), def, SolveOpt{
|
||||
Exports: []ExportEntry{
|
||||
{
|
||||
Type: ExporterTar,
|
||||
Output: fixedWriteCloser(tarFileW),
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
tarFileW.Close()
|
||||
|
||||
tarFileR, err := os.Open(tarFile)
|
||||
require.NoError(t, err)
|
||||
defer tarFileR.Close()
|
||||
tarR := tar.NewReader(tarFileR)
|
||||
|
||||
for {
|
||||
hd, err := tarR.Next()
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
require.NoError(t, err)
|
||||
if hd.Name == "foo/bar/" {
|
||||
require.Fail(t, "foo/bar/ should not be in the tar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/moby/buildkit/issues/3148
|
||||
func testMountStubsTimestamp(t *testing.T, sb integration.Sandbox) {
|
||||
c, err := New(sb.Context(), sb.Address())
|
||||
|
||||
@@ -42,9 +42,18 @@ func MountStubsCleaner(dir string, mounts []Mount) func() {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if st.Size() != 0 {
|
||||
if st.IsDir() {
|
||||
entries, err := os.ReadDir(p)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
continue
|
||||
}
|
||||
} else if st.Size() != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Back up the timestamps of the dir for reproducible builds
|
||||
// https://github.com/moby/buildkit/issues/3148
|
||||
dir := filepath.Dir(p)
|
||||
|
||||
Reference in New Issue
Block a user