Skip to content

Commit 418b199

Browse files
Merge pull request #54 from openhie/PLAT-676-archive-size-issue-fix
PLAT-676 TarSource write too long bug fix
2 parents 2926ae7 + 352becd commit 418b199

File tree

4 files changed

+25
-69
lines changed

4 files changed

+25
-69
lines changed

cli/src/cmd/version/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.2
1+
2.1.3

cli/src/core/deploy/deploy.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/docker/docker/api/types/mount"
2323
"github.com/docker/docker/api/types/network"
2424
"github.com/docker/docker/client"
25-
"github.com/docker/docker/pkg/archive"
2625
"github.com/docker/docker/pkg/stdcopy"
2726
"github.com/luno/jettison/errors"
2827
"github.com/luno/jettison/log"
@@ -112,7 +111,7 @@ func mountCustomPackage(ctx context.Context, cli *client.Client, customPackage c
112111
}
113112
}
114113

115-
customPackageReader, err := file.TarSource(CUSTOM_PACKAGE_LOCAL_PATH)
114+
customPackageReader, err := file.TarSource(customPackageTmpLocation)
116115
if err != nil {
117116
return err
118117
}
@@ -153,30 +152,12 @@ func copyCredsToInstantContainer() (err error) {
153152
return err
154153
}
155154

156-
dstInfo := archive.CopyInfo{
157-
Path: "/root/.docker/",
158-
Exists: true,
159-
IsDir: true,
160-
}
161-
162-
srcInfo, err := archive.CopyInfoSourcePath(dockerCredsPath, false)
163-
if err != nil {
164-
return errors.Wrap(err, "")
165-
}
166-
167-
srcArchive, err := archive.TarResource(srcInfo)
155+
preparedArchive, err := file.TarSource(dockerCredsPath)
168156
if err != nil {
169-
return errors.Wrap(err, "")
170-
}
171-
defer srcArchive.Close()
172-
173-
dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, dstInfo)
174-
if err != nil {
175-
return errors.Wrap(err, "")
157+
return err
176158
}
177-
defer preparedArchive.Close()
178159

179-
err = client.CopyToContainer(context.Background(), instantContainer.ID, dstDir, preparedArchive, types.CopyToContainerOptions{
160+
err = client.CopyToContainer(context.Background(), instantContainer.ID, "/root/.docker/", preparedArchive, types.CopyToContainerOptions{
180161
CopyUIDGID: true,
181162
})
182163
if err != nil {

cli/src/util/file/tar.go

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,42 @@ package file
22

33
import (
44
"archive/tar"
5-
"bufio"
6-
"bytes"
75
"io"
86
"os"
97
"path/filepath"
10-
"strings"
118

9+
"github.com/docker/docker/pkg/archive"
1210
"github.com/luno/jettison/errors"
1311
)
1412

1513
func TarSource(path string) (io.Reader, error) {
16-
var buf bytes.Buffer
17-
tw := tar.NewWriter(&buf)
18-
19-
ok := filepath.Walk(path, func(file string, fi os.FileInfo, err error) error {
20-
if err != nil {
21-
return errors.Wrap(err, "")
22-
}
23-
24-
header, err := tar.FileInfoHeader(fi, fi.Name())
25-
if err != nil {
26-
return errors.Wrap(err, "")
27-
}
28-
header.Name = strings.TrimPrefix(strings.Replace(file, path, "", -1), string(filepath.Separator))
29-
err = tw.WriteHeader(header)
30-
if err != nil {
31-
return errors.Wrap(err, "")
32-
}
33-
34-
f, err := os.Open(file)
35-
if err != nil {
36-
return errors.Wrap(err, "")
37-
}
38-
39-
if fi.IsDir() {
40-
return nil
41-
}
42-
43-
_, err = io.Copy(tw, f)
44-
if err != nil {
45-
return errors.Wrap(err, "")
46-
}
14+
dstInfo := archive.CopyInfo{
15+
Exists: true,
16+
IsDir: true,
17+
}
4718

48-
err = f.Close()
49-
if err != nil {
50-
return errors.Wrap(err, "")
51-
}
19+
_, err := os.Stat(path)
20+
if err != nil {
21+
return nil, errors.Wrap(err, "")
22+
}
5223

53-
return nil
54-
})
24+
srcInfo, err := archive.CopyInfoSourcePath(path, false)
25+
if err != nil {
26+
return nil, errors.Wrap(err, "")
27+
}
5528

56-
if ok != nil {
57-
return nil, ok
29+
srcArchive, err := archive.TarResource(srcInfo)
30+
if err != nil {
31+
return nil, errors.Wrap(err, "")
5832
}
5933

60-
err := tw.Close()
34+
_, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, dstInfo)
6135
if err != nil {
6236
return nil, errors.Wrap(err, "")
6337
}
38+
defer preparedArchive.Close()
6439

65-
return bufio.NewReader(&buf), nil
40+
return preparedArchive, nil
6641
}
6742

6843
func UntarSource(source, destination string) error {

cli/src/util/file/tar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func Test_tarSource(t *testing.T) {
133133
re, err := TarSource(tc.contentFileName)
134134
if err != nil {
135135
expectedErr := fs.PathError{
136-
Op: "lstat",
136+
Op: "stat",
137137
Err: unix.ENOENT,
138138
}
139139

0 commit comments

Comments
 (0)