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

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

Issue 2990503002: isolate: move creation of isolate into 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 75f37b8cecc572ae216329874e1b0d7ada2972ed..292e0cdd13a11ada0048fb1f378fbb540723e72f 100644
--- a/client/cmd/isolate/upload_tracker.go
+++ b/client/cmd/isolate/upload_tracker.go
@@ -15,9 +15,11 @@
package main
import (
+ "encoding/json"
"fmt"
"log"
"os"
+ "path/filepath"
humanize "github.com/dustin/go-humanize"
"github.com/luci/luci-go/common/isolated"
@@ -28,15 +30,16 @@ import (
type UploadTracker struct {
checker *Checker
uploader *Uploader
- files map[string]isolated.File
+ isol *isolated.Isolated
}
-// NewUploadTracker constructs an UploadTracker.
-func NewUploadTracker(checker *Checker, uploader *Uploader) *UploadTracker {
+// NewUploadTracker constructs an UploadTracker. It tracks uploaded files in isol.Files.
+func NewUploadTracker(checker *Checker, uploader *Uploader, isol *isolated.Isolated) *UploadTracker {
+ isol.Files = make(map[string]isolated.File)
return &UploadTracker{
checker: checker,
uploader: uploader,
- files: make(map[string]isolated.File),
+ isol: isol,
}
}
@@ -60,7 +63,7 @@ func (ut *UploadTracker) UploadDeps(parts partitionedDeps) error {
// Note: files may not have completed uploading until the tracker's Checker and
// Uploader have been closed.
func (ut *UploadTracker) Files() map[string]isolated.File {
- return ut.files
+ return ut.isol.Files
}
// populateSymlinks adds an isolated.File to files for each provided symlink
@@ -70,7 +73,7 @@ func (ut *UploadTracker) populateSymlinks(symlinks []*Item) error {
if err != nil {
return fmt.Errorf("unable to resolve symlink for %q: %v", item.Path, err)
}
- ut.files[item.RelPath] = isolated.SymLink(l)
+ ut.isol.Files[item.RelPath] = isolated.SymLink(l)
}
return nil
}
@@ -97,7 +100,7 @@ func (ut *UploadTracker) tarAndUploadFiles(smallFiles []*Item) error {
Mode: 0644, // Read
Digest: digest,
}
- ut.files[item.RelPath] = isolated.TarFile(item.Digest, int(item.Mode), item.Size)
+ ut.isol.Files[item.RelPath] = isolated.TarFile(item.Digest, int(item.Mode), item.Size)
ut.checker.AddItem(item, false, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
@@ -121,7 +124,7 @@ func (ut *UploadTracker) uploadFiles(files []*Item) error {
return err
}
item.Digest = d
- ut.files[item.RelPath] = isolated.BasicFile(item.Digest, int(item.Mode), item.Size)
+ ut.isol.Files[item.RelPath] = isolated.BasicFile(item.Digest, int(item.Mode), item.Size)
ut.checker.AddItem(item, false, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
return
@@ -134,3 +137,33 @@ 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 should only be called after UploadDeps.
+func (ut *UploadTracker) Finalize(isolatedPath string) (*Item, []byte, 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
+ }
+ isolItem := &Item{
+ Path: isolatedPath,
+ RelPath: filepath.Base(isolatedPath),
+ Digest: isolated.HashBytes(isolJSON),
+ Size: int64(len(isolJSON)),
+ }
+
+ // Check and upload isolate JSON.
+ ut.checker.AddItem(isolItem, true, func(item *Item, ps *isolatedclient.PushState) {
+ if ps == nil {
+ return
+ }
+ log.Printf("QUEUED %q for upload", item.RelPath)
+ ut.uploader.UploadBytes(item.RelPath, isolJSON, ps, func() {
+ log.Printf("UPLOADED %q", item.RelPath)
+ })
+ })
+
+ return isolItem, isolJSON, 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