Skip to content

Commit

Permalink
Merge pull request #4093 from jedevc/tempdir-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jedevc authored Aug 3, 2023
2 parents dd0053c + f751a91 commit 659fba6
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 409 deletions.
28 changes: 8 additions & 20 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ func testLocalSymlinkEscape(t *testing.T, sb integration.Sandbox) {
[[ $(readlink /mount/sub/bar) == "../../../etc/group" ]]
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
// point to absolute path that is not part of dir
fstest.Symlink("/etc/passwd", "foo"),
Expand All @@ -1477,7 +1477,6 @@ func testLocalSymlinkEscape(t *testing.T, sb integration.Sandbox) {
fstest.CreateFile("baz", []byte{}, 0600),
fstest.CreateFile("test.sh", test, 0700),
)
require.NoError(t, err)

local := llb.Local("mylocal", llb.FollowPaths([]string{
"test.sh", "foo", "sub/bar", "bax", "sub/sub2/file",
Expand Down Expand Up @@ -1568,20 +1567,17 @@ func testFileOpCopyRm(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)
defer c.Close()

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("myfile", []byte("data0"), 0600),
fstest.CreateDir("sub", 0700),
fstest.CreateFile("sub/foo", []byte("foo0"), 0600),
fstest.CreateFile("sub/bar", []byte("bar0"), 0600),
)
require.NoError(t, err)

dir2, err := integration.Tmpdir(
dir2 := integration.Tmpdir(
t,
fstest.CreateFile("file2", []byte("file2"), 0600),
)
require.NoError(t, err)

st := llb.Scratch().
File(
Expand Down Expand Up @@ -1694,14 +1690,13 @@ func testFileOpCopyIncludeExclude(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)
defer c.Close()

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("myfile", []byte("data0"), 0600),
fstest.CreateDir("sub", 0700),
fstest.CreateFile("sub/foo", []byte("foo0"), 0600),
fstest.CreateFile("sub/bar", []byte("bar0"), 0600),
)
require.NoError(t, err)

st := llb.Scratch().File(
llb.Copy(
Expand Down Expand Up @@ -1833,11 +1828,10 @@ func testLocalSourceWithDiffer(t *testing.T, sb integration.Sandbox, d llb.DiffT
require.NoError(t, err)
defer c.Close()

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("foo", []byte("foo"), 0600),
)
require.NoError(t, err)

tv := syscall.NsecToTimespec(time.Now().UnixNano())

Expand Down Expand Up @@ -2164,15 +2158,14 @@ func testFileOpRmWildcard(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)
defer c.Close()

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateDir("foo", 0700),
fstest.CreateDir("bar", 0700),
fstest.CreateFile("foo/target", []byte("foo0"), 0600),
fstest.CreateFile("bar/target", []byte("bar0"), 0600),
fstest.CreateFile("bar/remaining", []byte("bar1"), 0600),
)
require.NoError(t, err)

st := llb.Scratch().File(
llb.Copy(llb.Local("mylocal"), "foo", "foo").
Expand Down Expand Up @@ -7216,11 +7209,10 @@ func testParallelLocalBuilds(t *testing.T, sb integration.Sandbox) {
func(i int) {
eg.Go(func() error {
fn := fmt.Sprintf("test%d", i)
srcDir, err := integration.Tmpdir(
srcDir := integration.Tmpdir(
t,
fstest.CreateFile(fn, []byte("contents"), 0600),
)
require.NoError(t, err)

def, err := llb.Local("source").Marshal(sb.Context())
require.NoError(t, err)
Expand Down Expand Up @@ -9282,11 +9274,7 @@ func ensureFileContents(t *testing.T, path, expectedContents string) {
}

func makeSSHAgentSock(t *testing.T, agent agent.Agent) (p string, err error) {
tmpDir, err := integration.Tmpdir(t)
if err != nil {
return "", err
}

tmpDir := integration.Tmpdir(t)
sockPath := filepath.Join(tmpDir, "ssh_auth_sock")

l, err := net.Listen("unix", sockPath)
Expand Down
35 changes: 14 additions & 21 deletions frontend/dockerfile/dockerfile_addchecksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ func testAddChecksum(t *testing.T, sb integration.Sandbox) {
FROM scratch
ADD --checksum=%s %s /tmp/foo
`, digest.FromBytes(resp.Content).String(), server.URL+"/foo"))
dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
_, err := f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
Expand All @@ -64,12 +63,11 @@ ENV DIGEST=%s
ENV LINK=%s
ADD --checksum=${DIGEST} ${LINK} /tmp/foo
`, digest.FromBytes(resp.Content).String(), server.URL+"/foo"))
dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
_, err := f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
Expand All @@ -82,12 +80,11 @@ ADD --checksum=${DIGEST} ${LINK} /tmp/foo
FROM scratch
ADD --checksum=%s %s /tmp/foo
`, digest.FromBytes(nil).String(), server.URL+"/foo"))
dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
_, err := f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
Expand All @@ -100,12 +97,11 @@ ADD --checksum=%s %s /tmp/foo
FROM scratch
ADD --checksum=md5:7e55db001d319a94b0b713529a756623 %s /tmp/foo
`, server.URL+"/foo"))
dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
_, err := f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
Expand All @@ -118,12 +114,11 @@ ADD --checksum=md5:7e55db001d319a94b0b713529a756623 %s /tmp/foo
FROM scratch
ADD --checksum=unknown:%s %s /tmp/foo
`, digest.FromBytes(resp.Content).Encoded(), server.URL+"/foo"))
dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
_, err := f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
Expand All @@ -136,12 +131,11 @@ ADD --checksum=unknown:%s %s /tmp/foo
FROM scratch
ADD --checksum=%s %s /tmp/foo
`, digest.FromBytes(resp.Content).Encoded(), server.URL+"/foo"))
dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
_, err := f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
Expand All @@ -155,13 +149,12 @@ ADD --checksum=%s %s /tmp/foo
FROM scratch
ADD --checksum=%s foo /tmp/foo
`, digest.FromBytes(foo).String()))
dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("foo", foo, 0600),
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
_, err := f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
Expand Down
4 changes: 1 addition & 3 deletions frontend/dockerfile/dockerfile_addgit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ RUN cd /buildkit-chowned && \
require.NoError(t, err)
t.Logf("dockerfile=%s", dockerfile)

dir, err := integration.Tmpdir(t,
dir := integration.Tmpdir(t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)
defer os.RemoveAll(dir)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down
30 changes: 10 additions & 20 deletions frontend/dockerfile/dockerfile_heredoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ FROM scratch
COPY --from=build /dest /
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -138,11 +137,10 @@ COPY <<"EOF" rawslashfile3
EOF
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -208,11 +206,10 @@ FROM scratch
COPY --from=build /dest /dest
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -256,11 +253,10 @@ FROM scratch
COPY --from=build /dest /dest
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -305,11 +301,10 @@ FROM scratch
COPY --from=build /dest /dest
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -368,11 +363,10 @@ FROM scratch
COPY --from=build /dest /
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -458,11 +452,10 @@ FROM scratch
COPY --from=build /dest /
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -552,11 +545,10 @@ FROM scratch
COPY --from=build /dest /
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", []byte(dockerfile), 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -616,11 +608,10 @@ echo "hello world" >> /dest
EOF
`)

dir, err := integration.Tmpdir(
dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)

c, err := client.New(sb.Context(), sb.Address())
require.NoError(t, err)
Expand Down Expand Up @@ -650,11 +641,10 @@ EOF
COPY --from=base /dest /dest
`, target))

dir, err = integration.Tmpdir(
dir = integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)

destDir := t.TempDir()

Expand Down
Loading

0 comments on commit 659fba6

Please sign in to comment.