mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Replace json.Unmarshal with json.Decoder().Decode()
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
parent
92f4bd59ce
commit
26543e0309
5 changed files with 24 additions and 20 deletions
|
@ -233,7 +233,7 @@ func parseString(rest string) (*Node, map[string]bool, error) {
|
||||||
// parseJSON converts JSON arrays to an AST.
|
// parseJSON converts JSON arrays to an AST.
|
||||||
func parseJSON(rest string) (*Node, map[string]bool, error) {
|
func parseJSON(rest string) (*Node, map[string]bool, error) {
|
||||||
var myJson []interface{}
|
var myJson []interface{}
|
||||||
if err := json.Unmarshal([]byte(rest), &myJson); err != nil {
|
if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJson); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -107,12 +106,13 @@ func getArgs() *InitArgs {
|
||||||
func setupEnv(args *InitArgs) error {
|
func setupEnv(args *InitArgs) error {
|
||||||
// Get env
|
// Get env
|
||||||
var env []string
|
var env []string
|
||||||
content, err := ioutil.ReadFile(".dockerenv")
|
dockerenv, err := os.Open(".dockerenv")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to load environment variables: %v", err)
|
return fmt.Errorf("Unable to load environment variables: %v", err)
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(content, &env); err != nil {
|
defer dockerenv.Close()
|
||||||
return fmt.Errorf("Unable to unmarshal environment variables: %v", err)
|
if err := json.NewDecoder(dockerenv).Decode(&env); err != nil {
|
||||||
|
return fmt.Errorf("Unable to decode environment variables: %v", err)
|
||||||
}
|
}
|
||||||
// Propagate the plugin-specific container env variable
|
// Propagate the plugin-specific container env variable
|
||||||
env = append(env, "container="+os.Getenv("container"))
|
env = append(env, "container="+os.Getenv("container"))
|
||||||
|
|
|
@ -58,22 +58,26 @@ func (s *TagStore) Load(inTar io.ReadCloser, outStream io.Writer) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositoriesJson, err := ioutil.ReadFile(path.Join(tmpImageDir, "repo", "repositories"))
|
reposJSONFile, err := os.Open(path.Join(tmpImageDir, "repo", "repositories"))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
repositories := map[string]Repository{}
|
if !os.IsNotExist(err) {
|
||||||
if err := json.Unmarshal(repositoriesJson, &repositories); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer reposJSONFile.Close()
|
||||||
|
|
||||||
for imageName, tagMap := range repositories {
|
repositories := map[string]Repository{}
|
||||||
for tag, address := range tagMap {
|
if err := json.NewDecoder(reposJSONFile).Decode(&repositories); err != nil {
|
||||||
if err := s.SetLoad(imageName, tag, address, true, outStream); err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
|
for imageName, tagMap := range repositories {
|
||||||
|
for tag, address := range tagMap {
|
||||||
|
if err := s.SetLoad(imageName, tag, address, true, outStream); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -115,11 +115,12 @@ func (store *TagStore) save() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *TagStore) reload() error {
|
func (store *TagStore) reload() error {
|
||||||
jsonData, err := ioutil.ReadFile(store.path)
|
f, err := os.Open(store.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(jsonData, store); err != nil {
|
defer f.Close()
|
||||||
|
if err := json.NewDecoder(f).Decode(&store); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -58,8 +58,7 @@ func FromParam(p string) (Args, error) {
|
||||||
if len(p) == 0 {
|
if len(p) == 0 {
|
||||||
return args, nil
|
return args, nil
|
||||||
}
|
}
|
||||||
err := json.Unmarshal([]byte(p), &args)
|
if err := json.NewDecoder(strings.NewReader(p)).Decode(&args); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return args, nil
|
return args, nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue