Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: client/cmd/isolate/batch_archive.go

Issue 2933273002: Remove ReadJSONFile (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | client/internal/common/json.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/cmd/isolate/batch_archive.go
diff --git a/client/cmd/isolate/batch_archive.go b/client/cmd/isolate/batch_archive.go
index 17d2af62c8fe20353de1bda85dbd997f209e4963..a1dddcc98932def3278c0c938ae84d5ded6b8233 100644
--- a/client/cmd/isolate/batch_archive.go
+++ b/client/cmd/isolate/batch_archive.go
@@ -5,8 +5,10 @@
package main
import (
+ "encoding/json"
"errors"
"fmt"
+ "io"
"os"
"path/filepath"
"strings"
@@ -187,23 +189,39 @@ func (c *batchArchiveRun) main(a subcommands.Application, args []string) error {
// processGenJSON validates a genJSON file and returns the contents.
func processGenJSON(genJSONPath string) (*isolate.ArchiveOptions, error) {
+ f, err := os.Open(genJSONPath)
+ if err != nil {
+ return nil, fmt.Errorf("opening %s: %s", genJSONPath, err)
+ }
+ defer f.Close()
+
+ opts, err := processGenJSONData(f)
+ if err != nil {
+ return nil, fmt.Errorf("processing %s: %s", genJSONPath, err)
+ }
+ return opts, nil
+}
+
+// processGenJSONData performs the function of processGenJSON, but operates on an io.Reader.
+func processGenJSONData(r io.Reader) (*isolate.ArchiveOptions, error) {
data := &struct {
Args []string
Dir string
Version int
}{}
- if err := common.ReadJSONFile(genJSONPath, data); err != nil {
- return nil, err
+ if err := json.NewDecoder(r).Decode(data); err != nil {
+ return nil, fmt.Errorf("failed to decode: %s", err)
}
+
if data.Version != isolate.IsolatedGenJSONVersion {
- return nil, fmt.Errorf("invalid version %d in %s", data.Version, genJSONPath)
+ return nil, fmt.Errorf("invalid version %d", data.Version)
}
if !common.IsDirectory(data.Dir) {
- return nil, fmt.Errorf("invalid dir %s in %s", data.Dir, genJSONPath)
+ return nil, fmt.Errorf("invalid dir %s", data.Dir)
}
opts, err := parseArchiveCMD(data.Args, data.Dir)
if err != nil {
- return nil, fmt.Errorf("invalid archive command in %s: %s", genJSONPath, err)
+ return nil, fmt.Errorf("invalid archive command: %s", err)
}
return opts, nil
}
« no previous file with comments | « no previous file | client/internal/common/json.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698