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

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

Issue 2985873002: Pass a Writer to Finalize for JSON dumping. (Closed)
Patch Set: Created 3 years, 5 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 | « client/cmd/isolate/exp_archive.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/cmd/isolate/upload_tracker.go
diff --git a/client/cmd/isolate/upload_tracker.go b/client/cmd/isolate/upload_tracker.go
index 0c2fbe2a2db496a7deef3006e61a950afd37ef9c..305e4b9a16d6cea568d798702e6806a8daf2dcd3 100644
--- a/client/cmd/isolate/upload_tracker.go
+++ b/client/cmd/isolate/upload_tracker.go
@@ -17,6 +17,7 @@ package main
import (
"encoding/json"
"fmt"
+ "io"
"io/ioutil"
"log"
"os"
@@ -145,7 +146,7 @@ func (ut *UploadTracker) uploadFiles(files []*Item) error {
// If dumpJSONPath is non-empty, the digest is also written to that path as
// JSON (in the same format as batch_archive).
// Finalize should only be called after UploadDeps.
-func (ut *UploadTracker) Finalize(isolatedPath, dumpJSONPath string) (isolated.HexDigest, error) {
+func (ut *UploadTracker) Finalize(isolatedPath string, dumpJSONWriter io.Writer) (isolated.HexDigest, error) {
// Marshal the isolated file into JSON, and create an Item to describe it.
isolJSON, err := json.Marshal(ut.isol)
if err != nil {
@@ -186,30 +187,22 @@ func (ut *UploadTracker) Finalize(isolatedPath, dumpJSONPath string) (isolated.H
fmt.Printf("%s\t%s\n", isolItem.Digest, filepath.Base(isolatedPath))
- if err := dumpJSON(isolatedPath, dumpJSONPath, isolItem); err != nil {
+ if err := dumpJSON(isolatedPath, dumpJSONWriter, isolItem); err != nil {
return "", err
}
return isolItem.Digest, nil
}
-func dumpJSON(isolatedPath, dumpJSONPath string, isolItem *Item) error {
- if dumpJSONPath == "" {
- return nil
- }
+func dumpJSON(isolatedPath string, dumpJSONWriter io.Writer, isolItem *Item) error {
// The name is the base name of the isolated file, extension stripped.
name := filepath.Base(isolatedPath)
if i := strings.LastIndex(name, "."); i != -1 {
name = name[:i]
}
- j, err := json.Marshal(map[string]isolated.HexDigest{
+
+ enc := json.NewEncoder(dumpJSONWriter)
+ return enc.Encode(map[string]isolated.HexDigest{
name: isolItem.Digest,
})
- if err != nil {
- return err
- }
- if err := ioutil.WriteFile(dumpJSONPath, j, 0644); err != nil {
- return err
- }
- return nil
}
« no previous file with comments | « client/cmd/isolate/exp_archive.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698