Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
| ... | ... |
@@ -740,6 +740,15 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w |
| 740 | 740 |
} |
| 741 | 741 |
} |
| 742 | 742 |
|
| 743 |
+ var ( |
|
| 744 |
+ opErr error |
|
| 745 |
+ useJSON = version.GreaterThan("1.0")
|
|
| 746 |
+ ) |
|
| 747 |
+ |
|
| 748 |
+ if useJSON {
|
|
| 749 |
+ w.Header().Set("Content-Type", "application/json")
|
|
| 750 |
+ } |
|
| 751 |
+ |
|
| 743 | 752 |
if image != "" { //pull
|
| 744 | 753 |
if tag == "" {
|
| 745 | 754 |
image, tag = parsers.ParseRepositoryTag(image) |
| ... | ... |
@@ -756,17 +765,10 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w |
| 756 | 756 |
MetaHeaders: metaHeaders, |
| 757 | 757 |
AuthConfig: authConfig, |
| 758 | 758 |
OutStream: utils.NewWriteFlusher(w), |
| 759 |
- } |
|
| 760 |
- if version.GreaterThan("1.0") {
|
|
| 761 |
- imagePullConfig.Json = true |
|
| 762 |
- w.Header().Set("Content-Type", "application/json")
|
|
| 763 |
- } else {
|
|
| 764 |
- imagePullConfig.Json = false |
|
| 759 |
+ Json: useJSON, |
|
| 765 | 760 |
} |
| 766 | 761 |
|
| 767 |
- if err := s.daemon.Repositories().Pull(image, tag, imagePullConfig); err != nil {
|
|
| 768 |
- return err |
|
| 769 |
- } |
|
| 762 |
+ opErr = s.daemon.Repositories().Pull(image, tag, imagePullConfig) |
|
| 770 | 763 |
} else { //import
|
| 771 | 764 |
if tag == "" {
|
| 772 | 765 |
repo, tag = parsers.ParseRepositoryTag(repo) |
| ... | ... |
@@ -777,12 +779,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w |
| 777 | 777 |
Changes: r.Form["changes"], |
| 778 | 778 |
InConfig: r.Body, |
| 779 | 779 |
OutStream: utils.NewWriteFlusher(w), |
| 780 |
- } |
|
| 781 |
- if version.GreaterThan("1.0") {
|
|
| 782 |
- imageImportConfig.Json = true |
|
| 783 |
- w.Header().Set("Content-Type", "application/json")
|
|
| 784 |
- } else {
|
|
| 785 |
- imageImportConfig.Json = false |
|
| 780 |
+ Json: useJSON, |
|
| 786 | 781 |
} |
| 787 | 782 |
|
| 788 | 783 |
newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
|
| ... | ... |
@@ -791,9 +788,12 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w |
| 791 | 791 |
} |
| 792 | 792 |
imageImportConfig.ContainerConfig = newConfig |
| 793 | 793 |
|
| 794 |
- if err := s.daemon.Repositories().Import(src, repo, tag, imageImportConfig); err != nil {
|
|
| 795 |
- return err |
|
| 796 |
- } |
|
| 794 |
+ opErr = s.daemon.Repositories().Import(src, repo, tag, imageImportConfig) |
|
| 795 |
+ } |
|
| 796 |
+ |
|
| 797 |
+ if opErr != nil {
|
|
| 798 |
+ sf := streamformatter.NewStreamFormatter(useJSON) |
|
| 799 |
+ return fmt.Errorf(string(sf.FormatError(opErr))) |
|
| 797 | 800 |
} |
| 798 | 801 |
|
| 799 | 802 |
return nil |