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

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

Issue 2991503002: isolate: Finalize the isolate in UploadTracker (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 292e0cdd13a11ada0048fb1f378fbb540723e72f..0c2fbe2a2db496a7deef3006e61a950afd37ef9c 100644
--- a/client/cmd/isolate/upload_tracker.go
+++ b/client/cmd/isolate/upload_tracker.go
@@ -17,9 +17,11 @@ package main
import (
"encoding/json"
"fmt"
+ "io/ioutil"
"log"
"os"
"path/filepath"
+ "strings"
humanize "github.com/dustin/go-humanize"
"github.com/luci/luci-go/common/isolated"
@@ -138,14 +140,16 @@ func (ut *UploadTracker) uploadFiles(files []*Item) error {
return nil
}
-// Finalize creates and uploads the isolate JSON at the isolatePath.
-// It returns the corresponding Item and its contents.
+// Finalize creates and uploads the isolate JSON at the isolatePath, and closes the checker and uploader.
+// It returns the isolate digest.
+// 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 string) (*Item, []byte, error) {
+func (ut *UploadTracker) Finalize(isolatedPath, dumpJSONPath string) (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 {
- return nil, []byte{}, err
+ return "", err
}
isolItem := &Item{
Path: isolatedPath,
@@ -165,5 +169,47 @@ func (ut *UploadTracker) Finalize(isolatedPath string) (*Item, []byte, error) {
})
})
- return isolItem, isolJSON, nil
+ // Make sure that all pending items have been checked.
+ if err := ut.checker.Close(); err != nil {
+ return "", err
+ }
+
+ // Make sure that all the uploads have completed successfully.
+ if err := ut.uploader.Close(); err != nil {
+ return "", err
+ }
+
+ // Write the isolated file, and emit its digest to stdout.
+ if err := ioutil.WriteFile(isolatedPath, isolJSON, 0644); err != nil {
+ return "", err
+ }
+
+ fmt.Printf("%s\t%s\n", isolItem.Digest, filepath.Base(isolatedPath))
+
+ if err := dumpJSON(isolatedPath, dumpJSONPath, isolItem); err != nil {
+ return "", err
+ }
+
+ return isolItem.Digest, nil
+}
+
+func dumpJSON(isolatedPath, dumpJSONPath string, isolItem *Item) error {
+ if dumpJSONPath == "" {
+ return nil
+ }
+ // 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{
+ 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