зеркало из https://github.com/microsoft/docker.git
Fix for Daemon crashing when wildcards are used for COPY/ADD
in the filename and the command itself Closes #12267 Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Родитель
aebeefa886
Коммит
82daa43844
|
@ -156,6 +156,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp
|
||||||
dest,
|
dest,
|
||||||
allowRemote,
|
allowRemote,
|
||||||
allowDecompression,
|
allowDecompression,
|
||||||
|
true,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -226,7 +227,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath string, destPath string, allowRemote bool, allowDecompression bool) error {
|
func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath string, destPath string, allowRemote bool, allowDecompression bool, allowWildcards bool) error {
|
||||||
|
|
||||||
if origPath != "" && origPath[0] == '/' && len(origPath) > 1 {
|
if origPath != "" && origPath[0] == '/' && len(origPath) > 1 {
|
||||||
origPath = origPath[1:]
|
origPath = origPath[1:]
|
||||||
|
@ -351,7 +352,7 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deal with wildcards
|
// Deal with wildcards
|
||||||
if ContainsWildcards(origPath) {
|
if allowWildcards && ContainsWildcards(origPath) {
|
||||||
for _, fileInfo := range b.context.GetSums() {
|
for _, fileInfo := range b.context.GetSums() {
|
||||||
if fileInfo.Name() == "" {
|
if fileInfo.Name() == "" {
|
||||||
continue
|
continue
|
||||||
|
@ -361,7 +362,9 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
calcCopyInfo(b, cmdName, cInfos, fileInfo.Name(), destPath, allowRemote, allowDecompression)
|
// Note we set allowWildcards to false in case the name has
|
||||||
|
// a * in it
|
||||||
|
calcCopyInfo(b, cmdName, cInfos, fileInfo.Name(), destPath, allowRemote, allowDecompression, false)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1113,10 +1113,10 @@ func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) {
|
||||||
"dir/nested_dir/nest_nest_file": "2 times nested",
|
"dir/nested_dir/nest_nest_file": "2 times nested",
|
||||||
"dirt": "dirty",
|
"dirt": "dirty",
|
||||||
})
|
})
|
||||||
defer ctx.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
id1, err := buildImageFromContext(name, ctx, true)
|
id1, err := buildImageFromContext(name, ctx, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1155,6 +1155,31 @@ func (s *DockerSuite) TestBuildCopyWildcardNoFind(c *check.C) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestBuildCopyWildcardInName(c *check.C) {
|
||||||
|
name := "testcopywildcardinname"
|
||||||
|
defer deleteImages(name)
|
||||||
|
ctx, err := fakeContext(`FROM busybox
|
||||||
|
COPY *.txt /tmp/
|
||||||
|
RUN [ "$(cat /tmp/\*.txt)" = 'hi there' ]
|
||||||
|
`, map[string]string{"*.txt": "hi there"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
// Normally we would do c.Fatal(err) here but given that
|
||||||
|
// the odds of this failing are so rare, it must be because
|
||||||
|
// the OS we're running the client on doesn't support * in
|
||||||
|
// filenames (like windows). So, instead of failing the test
|
||||||
|
// just let it pass. Then we don't need to explicitly
|
||||||
|
// say which OSs this works on or not.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
_, err = buildImageFromContext(name, ctx, true)
|
||||||
|
if err != nil {
|
||||||
|
c.Fatalf("should have built: %q", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
|
func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
|
||||||
name := "testcopywildcardcache"
|
name := "testcopywildcardcache"
|
||||||
ctx, err := fakeContext(`FROM busybox
|
ctx, err := fakeContext(`FROM busybox
|
||||||
|
|
|
@ -663,7 +663,6 @@ func fakeContextAddDockerfile(ctx *FakeContext, dockerfile string) error {
|
||||||
func fakeContext(dockerfile string, files map[string]string) (*FakeContext, error) {
|
func fakeContext(dockerfile string, files map[string]string) (*FakeContext, error) {
|
||||||
ctx, err := fakeContextWithFiles(files)
|
ctx, err := fakeContextWithFiles(files)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Close()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := fakeContextAddDockerfile(ctx, dockerfile); err != nil {
|
if err := fakeContextAddDockerfile(ctx, dockerfile); err != nil {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче