Skip to content

Commit

Permalink
Fix copy into workdir for a single file
Browse files Browse the repository at this point in the history
When copying a single file to the workdir make sure to create the workdir
and not to overwrite it as file.

Fixes containers/podman#10671

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Jun 14, 2021
1 parent 8d08247 commit fd7af1a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion add.go
Expand Up @@ -287,7 +287,7 @@ func (b *Builder) Add(destination string, extract bool, options AddAndCopyOption
destination = tmpDestination
}
}
destMustBeDirectory := (len(sources) > 1) || strings.HasSuffix(destination, string(os.PathSeparator))
destMustBeDirectory := (len(sources) > 1) || strings.HasSuffix(destination, string(os.PathSeparator)) || destination == b.WorkDir()
destCanBeFile := false
if len(sources) == 1 {
if len(remoteSources) == 1 {
Expand Down
14 changes: 14 additions & 0 deletions tests/bud.bats
Expand Up @@ -1830,6 +1830,20 @@ _EOF
test -s "${root}"/subdir/file2.txt
}

# regression test for https://github.com/containers/podman/issues/10671
@test "bud-copy-workdir --layers" {
_prefetch alpine

target=testimage
run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t ${target} -f Dockerfile.2 ${TESTSDIR}/bud/copy-workdir
run_buildah from ${target}
cid="$output"
run_buildah mount "${cid}"
root="$output"
test -d "${root}"/subdir
test -s "${root}"/subdir/file1.txt
}

@test "bud-build-arg-cache" {
_prefetch busybox alpine
target=derived-image
Expand Down
4 changes: 4 additions & 0 deletions tests/bud/copy-workdir/Dockerfile.2
@@ -0,0 +1,4 @@
FROM alpine
WORKDIR /subdir
COPY file1.txt /subdir
RUN ls

0 comments on commit fd7af1a

Please sign in to comment.