mirror of https://github.com/containers/podman.git
podman-remote,bindings: trim context path correctly when its emptydir
podman-remote converts and sends absolute path as context when its an emptydir by adding additional seperator however it should correctly trim the path and not add additional seperator for such use cases. Closes: BZ#2145054 Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
parent
3fbf62e968
commit
553df8748b
|
@ -647,23 +647,27 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
separator := string(filepath.Separator)
|
||||||
// check if what we are given is an empty dir, if so then continue w/ it. Else return.
|
// check if what we are given is an empty dir, if so then continue w/ it. Else return.
|
||||||
// if we are given a file or a symlink, we do not want to exclude it.
|
// if we are given a file or a symlink, we do not want to exclude it.
|
||||||
if d.IsDir() && s == path {
|
if s == path {
|
||||||
var p *os.File
|
separator = ""
|
||||||
p, err = os.Open(path)
|
if d.IsDir() {
|
||||||
if err != nil {
|
var p *os.File
|
||||||
return err
|
p, err = os.Open(path)
|
||||||
}
|
if err != nil {
|
||||||
defer p.Close()
|
return err
|
||||||
_, err = p.Readdir(1)
|
}
|
||||||
if err != io.EOF {
|
defer p.Close()
|
||||||
return nil // non empty root dir, need to return
|
_, err = p.Readdir(1)
|
||||||
} else if err != nil {
|
if err != io.EOF {
|
||||||
logrus.Errorf("While reading directory %v: %v", path, err)
|
return nil // non empty root dir, need to return
|
||||||
|
} else if err != nil {
|
||||||
|
logrus.Errorf("While reading directory %v: %v", path, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name := filepath.ToSlash(strings.TrimPrefix(path, s+string(filepath.Separator)))
|
name := filepath.ToSlash(strings.TrimPrefix(path, s+separator))
|
||||||
|
|
||||||
excluded, err := pm.Matches(name) //nolint:staticcheck
|
excluded, err := pm.Matches(name) //nolint:staticcheck
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -386,6 +386,41 @@ RUN exit 5`, ALPINE)
|
||||||
Expect(data).To(ContainSubstring(buildah.Version))
|
Expect(data).To(ContainSubstring(buildah.Version))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman-remote send correct path to copier", func() {
|
||||||
|
if IsRemote() {
|
||||||
|
podmanTest.StopRemoteService()
|
||||||
|
podmanTest.StartRemoteService()
|
||||||
|
} else {
|
||||||
|
Skip("Only valid at remote test, case works fine for regular podman and buildah")
|
||||||
|
}
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
// Write target and fake files
|
||||||
|
targetSubPath := filepath.Join(cwd, "emptydir")
|
||||||
|
if _, err = os.Stat(targetSubPath); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
err = os.Mkdir(targetSubPath, 0755)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
containerfile := fmt.Sprintf(`FROM %s
|
||||||
|
COPY /* /dir`, ALPINE)
|
||||||
|
|
||||||
|
containerfilePath := filepath.Join(cwd, "ContainerfilePathToCopier")
|
||||||
|
err = os.WriteFile(containerfilePath, []byte(containerfile), 0644)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "-f", "ContainerfilePathToCopier", targetSubPath})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
// NOTE: Docker and buildah both should error when `COPY /* /dir` is done on emptydir
|
||||||
|
// as context. However buildkit simply ignores this so when buildah also starts ignoring
|
||||||
|
// for such case edit this test to return 0 and check that no `/dir` should be in the result.
|
||||||
|
Expect(session).Should(Exit(125))
|
||||||
|
Expect(session.ErrorToString()).To(ContainSubstring("can't make relative to"))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman remote test container/docker file is not inside context dir", func() {
|
It("podman remote test container/docker file is not inside context dir", func() {
|
||||||
// Given
|
// Given
|
||||||
// Switch to temp dir and restore it afterwards
|
// Switch to temp dir and restore it afterwards
|
||||||
|
|
Loading…
Reference in New Issue