Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue where copyup could fail with ENOENT #9383

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,17 @@ func (c *Container) mountNamedVolume(v *ContainerNamedVolume, mountpoint string)
if !srcStat.IsDir() {
return vol, nil
}
// Read contents, do not bother continuing if it's empty. Fixes
// a bizarre issue where something copier.Get will ENOENT on
// empty directories and sometimes it will not.
// RHBZ#1928643
srcContents, err := ioutil.ReadDir(srcDir)
if err != nil {
return nil, errors.Wrapf(err, "error reading contents of source directory for copy up into volume %s", vol.Name())
}
if len(srcContents) == 0 {
return vol, nil
}

// Buildah Copier accepts a reader, so we'll need a pipe.
reader, writer := io.Pipe()
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ RUN sh -c "cd /etc/apk && ln -s ../../testfile"`
Expect(outputSession.OutputToString()).To(Equal(baselineOutput))
})

It("podman named volume copyup empty directory", func() {
baselineSession := podmanTest.Podman([]string{"run", "--rm", "-t", "-i", ALPINE, "ls", "/srv"})
baselineSession.WaitWithDefaultTimeout()
Expect(baselineSession.ExitCode()).To(Equal(0))
baselineOutput := baselineSession.OutputToString()

outputSession := podmanTest.Podman([]string{"run", "-t", "-i", "-v", "/srv", ALPINE, "ls", "/srv"})
outputSession.WaitWithDefaultTimeout()
Expect(outputSession.ExitCode()).To(Equal(0))
Expect(outputSession.OutputToString()).To(Equal(baselineOutput))
})

It("podman read-only tmpfs conflict with volume", func() {
session := podmanTest.Podman([]string{"run", "--rm", "-t", "-i", "--read-only", "-v", "tmp_volume:" + dest, ALPINE, "touch", dest + "/a"})
session.WaitWithDefaultTimeout()
Expand Down