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

Side by Side Diff: client/cmd/isolate/archive.go

Issue 2936713003: Sever isolate cmd dependency on Canceler. (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 unified diff | Download patch
« no previous file with comments | « no previous file | client/cmd/isolate/batch_archive.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "log" 10 "log"
11 "os" 11 "os"
12 "os/signal"
12 "path/filepath" 13 "path/filepath"
13 "time" 14 "time"
14 15
15 "github.com/golang/protobuf/proto" 16 "github.com/golang/protobuf/proto"
16 "github.com/maruel/subcommands" 17 "github.com/maruel/subcommands"
17 18
18 "github.com/luci/luci-go/client/archiver" 19 "github.com/luci/luci-go/client/archiver"
19 "github.com/luci/luci-go/client/internal/common"
20 "github.com/luci/luci-go/client/isolate" 20 "github.com/luci/luci-go/client/isolate"
21 "github.com/luci/luci-go/common/auth" 21 "github.com/luci/luci-go/common/auth"
22 "github.com/luci/luci-go/common/data/text/units" 22 "github.com/luci/luci-go/common/data/text/units"
23 logpb "github.com/luci/luci-go/common/eventlog/proto" 23 logpb "github.com/luci/luci-go/common/eventlog/proto"
24 "github.com/luci/luci-go/common/isolatedclient" 24 "github.com/luci/luci-go/common/isolatedclient"
25 ) 25 )
26 26
27 func cmdArchive(defaultAuthOpts auth.Options) *subcommands.Command { 27 func cmdArchive(defaultAuthOpts auth.Options) *subcommands.Command {
28 return &subcommands.Command{ 28 return &subcommands.Command{
29 UsageLine: "archive <options>", 29 UsageLine: "archive <options>",
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if c.defaultFlags.Quiet { 68 if c.defaultFlags.Quiet {
69 prefix = "" 69 prefix = ""
70 } 70 }
71 start := time.Now() 71 start := time.Now()
72 client, err := c.createAuthClient() 72 client, err := c.createAuthClient()
73 if err != nil { 73 if err != nil {
74 return err 74 return err
75 } 75 }
76 ctx := c.defaultFlags.MakeLoggingContext(os.Stderr) 76 ctx := c.defaultFlags.MakeLoggingContext(os.Stderr)
77 arch := archiver.New(ctx, isolatedclient.New(nil, client, c.isolatedFlag s.ServerURL, c.isolatedFlags.Namespace, nil, nil), out) 77 arch := archiver.New(ctx, isolatedclient.New(nil, client, c.isolatedFlag s.ServerURL, c.isolatedFlags.Namespace, nil, nil), out)
78 » common.CancelOnCtrlC(arch) 78 » CancelOnCtrlC(arch)
79 item := isolate.Archive(arch, &c.ArchiveOptions) 79 item := isolate.Archive(arch, &c.ArchiveOptions)
80 item.WaitForHashed() 80 item.WaitForHashed()
81 if err = item.Error(); err != nil { 81 if err = item.Error(); err != nil {
82 fmt.Printf("%s%s %s\n", prefix, filepath.Base(c.Isolate), err) 82 fmt.Printf("%s%s %s\n", prefix, filepath.Base(c.Isolate), err)
83 } else { 83 } else {
84 fmt.Printf("%s%s %s\n", prefix, item.Digest(), filepath.Base(c. Isolate)) 84 fmt.Printf("%s%s %s\n", prefix, item.Digest(), filepath.Base(c. Isolate))
85 } 85 }
86 if err2 := arch.Close(); err == nil { 86 if err2 := arch.Close(); err == nil {
87 err = err2 87 err = err2
88 } 88 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) 123 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
124 return 1 124 return 1
125 } 125 }
126 defer cl.Close() 126 defer cl.Close()
127 if err := c.main(a, args); err != nil { 127 if err := c.main(a, args); err != nil {
128 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) 128 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
129 return 1 129 return 1
130 } 130 }
131 return 0 131 return 0
132 } 132 }
133
134 // CancelOnCtrlC is a temporary copy of the CancelOnCtrlC in internal/common/con current.go
135 // This is needed until the old archive and batcharchive code (which uses Cancel ers) is removed.
136 // It operates on a concrete Archiver to avoid the dependency on Canceler.
137 func CancelOnCtrlC(arch *archiver.Archiver) {
138 interrupted := make(chan os.Signal, 1)
139 signal.Notify(interrupted, os.Interrupt)
140 go func() {
141 defer signal.Stop(interrupted)
142 select {
143 case <-interrupted:
144 arch.Cancel(errors.New("Ctrl-C"))
145 case <-arch.Channel():
146 }
147 }()
148 }
OLDNEW
« no previous file with comments | « no previous file | client/cmd/isolate/batch_archive.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698