Fix for Daemon crashing when wildcards are used for COPY/ADD
| ... | ... |
@@ -155,6 +155,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp |
| 155 | 155 |
dest, |
| 156 | 156 |
allowRemote, |
| 157 | 157 |
allowDecompression, |
| 158 |
+ true, |
|
| 158 | 159 |
); err != nil {
|
| 159 | 160 |
return err |
| 160 | 161 |
} |
| ... | ... |
@@ -225,7 +226,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp |
| 225 | 225 |
return nil |
| 226 | 226 |
} |
| 227 | 227 |
|
| 228 |
-func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath string, destPath string, allowRemote bool, allowDecompression bool) error {
|
|
| 228 |
+func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath string, destPath string, allowRemote bool, allowDecompression bool, allowWildcards bool) error {
|
|
| 229 | 229 |
|
| 230 | 230 |
if origPath != "" && origPath[0] == '/' && len(origPath) > 1 {
|
| 231 | 231 |
origPath = origPath[1:] |
| ... | ... |
@@ -350,7 +351,7 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri |
| 350 | 350 |
} |
| 351 | 351 |
|
| 352 | 352 |
// Deal with wildcards |
| 353 |
- if ContainsWildcards(origPath) {
|
|
| 353 |
+ if allowWildcards && ContainsWildcards(origPath) {
|
|
| 354 | 354 |
for _, fileInfo := range b.context.GetSums() {
|
| 355 | 355 |
if fileInfo.Name() == "" {
|
| 356 | 356 |
continue |
| ... | ... |
@@ -360,7 +361,9 @@ func calcCopyInfo(b *Builder, cmdName string, cInfos *[]*copyInfo, origPath stri |
| 360 | 360 |
continue |
| 361 | 361 |
} |
| 362 | 362 |
|
| 363 |
- calcCopyInfo(b, cmdName, cInfos, fileInfo.Name(), destPath, allowRemote, allowDecompression) |
|
| 363 |
+ // Note we set allowWildcards to false in case the name has |
|
| 364 |
+ // a * in it |
|
| 365 |
+ calcCopyInfo(b, cmdName, cInfos, fileInfo.Name(), destPath, allowRemote, allowDecompression, false) |
|
| 364 | 366 |
} |
| 365 | 367 |
return nil |
| 366 | 368 |
} |
| ... | ... |
@@ -1112,10 +1112,10 @@ func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) {
|
| 1112 | 1112 |
"dir/nested_dir/nest_nest_file": "2 times nested", |
| 1113 | 1113 |
"dirt": "dirty", |
| 1114 | 1114 |
}) |
| 1115 |
- defer ctx.Close() |
|
| 1116 | 1115 |
if err != nil {
|
| 1117 | 1116 |
c.Fatal(err) |
| 1118 | 1117 |
} |
| 1118 |
+ defer ctx.Close() |
|
| 1119 | 1119 |
|
| 1120 | 1120 |
id1, err := buildImageFromContext(name, ctx, true) |
| 1121 | 1121 |
if err != nil {
|
| ... | ... |
@@ -1154,6 +1154,31 @@ func (s *DockerSuite) TestBuildCopyWildcardNoFind(c *check.C) {
|
| 1154 | 1154 |
|
| 1155 | 1155 |
} |
| 1156 | 1156 |
|
| 1157 |
+func (s *DockerSuite) TestBuildCopyWildcardInName(c *check.C) {
|
|
| 1158 |
+ name := "testcopywildcardinname" |
|
| 1159 |
+ defer deleteImages(name) |
|
| 1160 |
+ ctx, err := fakeContext(`FROM busybox |
|
| 1161 |
+ COPY *.txt /tmp/ |
|
| 1162 |
+ RUN [ "$(cat /tmp/\*.txt)" = 'hi there' ] |
|
| 1163 |
+ `, map[string]string{"*.txt": "hi there"})
|
|
| 1164 |
+ |
|
| 1165 |
+ if err != nil {
|
|
| 1166 |
+ // Normally we would do c.Fatal(err) here but given that |
|
| 1167 |
+ // the odds of this failing are so rare, it must be because |
|
| 1168 |
+ // the OS we're running the client on doesn't support * in |
|
| 1169 |
+ // filenames (like windows). So, instead of failing the test |
|
| 1170 |
+ // just let it pass. Then we don't need to explicitly |
|
| 1171 |
+ // say which OSs this works on or not. |
|
| 1172 |
+ return |
|
| 1173 |
+ } |
|
| 1174 |
+ defer ctx.Close() |
|
| 1175 |
+ |
|
| 1176 |
+ _, err = buildImageFromContext(name, ctx, true) |
|
| 1177 |
+ if err != nil {
|
|
| 1178 |
+ c.Fatalf("should have built: %q", err)
|
|
| 1179 |
+ } |
|
| 1180 |
+} |
|
| 1181 |
+ |
|
| 1157 | 1182 |
func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
|
| 1158 | 1183 |
name := "testcopywildcardcache" |
| 1159 | 1184 |
ctx, err := fakeContext(`FROM busybox |
| ... | ... |
@@ -687,7 +687,6 @@ func fakeContextAddDockerfile(ctx *FakeContext, dockerfile string) error {
|
| 687 | 687 |
func fakeContext(dockerfile string, files map[string]string) (*FakeContext, error) {
|
| 688 | 688 |
ctx, err := fakeContextWithFiles(files) |
| 689 | 689 |
if err != nil {
|
| 690 |
- ctx.Close() |
|
| 691 | 690 |
return nil, err |
| 692 | 691 |
} |
| 693 | 692 |
if err := fakeContextAddDockerfile(ctx, dockerfile); err != nil {
|