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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | client/internal/common/json.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 "encoding/json"
8 "errors" 9 "errors"
9 "fmt" 10 "fmt"
11 "io"
10 "os" 12 "os"
11 "path/filepath" 13 "path/filepath"
12 "strings" 14 "strings"
13 "sync" 15 "sync"
14 "time" 16 "time"
15 17
16 "github.com/maruel/subcommands" 18 "github.com/maruel/subcommands"
17 19
18 "github.com/luci/luci-go/client/archiver" 20 "github.com/luci/luci-go/client/archiver"
19 "github.com/luci/luci-go/client/internal/common" 21 "github.com/luci/luci-go/client/internal/common"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 stats := arch.Stats() 182 stats := arch.Stats()
181 fmt.Fprintf(os.Stderr, "Hits : %5d (%s)\n", stats.TotalHits() , stats.TotalBytesHits()) 183 fmt.Fprintf(os.Stderr, "Hits : %5d (%s)\n", stats.TotalHits() , stats.TotalBytesHits())
182 fmt.Fprintf(os.Stderr, "Misses : %5d (%s)\n", stats.TotalMisses (), stats.TotalBytesPushed()) 184 fmt.Fprintf(os.Stderr, "Misses : %5d (%s)\n", stats.TotalMisses (), stats.TotalBytesPushed())
183 fmt.Fprintf(os.Stderr, "Duration: %s\n", units.Round(duration, t ime.Millisecond)) 185 fmt.Fprintf(os.Stderr, "Duration: %s\n", units.Round(duration, t ime.Millisecond))
184 } 186 }
185 return err 187 return err
186 } 188 }
187 189
188 // processGenJSON validates a genJSON file and returns the contents. 190 // processGenJSON validates a genJSON file and returns the contents.
189 func processGenJSON(genJSONPath string) (*isolate.ArchiveOptions, error) { 191 func processGenJSON(genJSONPath string) (*isolate.ArchiveOptions, error) {
192 f, err := os.Open(genJSONPath)
193 if err != nil {
194 return nil, fmt.Errorf("opening %s: %s", genJSONPath, err)
195 }
196 defer f.Close()
197
198 opts, err := processGenJSONData(f)
199 if err != nil {
200 return nil, fmt.Errorf("processing %s: %s", genJSONPath, err)
201 }
202 return opts, nil
203 }
204
205 // processGenJSONData performs the function of processGenJSON, but operates on a n io.Reader.
206 func processGenJSONData(r io.Reader) (*isolate.ArchiveOptions, error) {
190 data := &struct { 207 data := &struct {
191 Args []string 208 Args []string
192 Dir string 209 Dir string
193 Version int 210 Version int
194 }{} 211 }{}
195 » if err := common.ReadJSONFile(genJSONPath, data); err != nil { 212 » if err := json.NewDecoder(r).Decode(data); err != nil {
196 » » return nil, err 213 » » return nil, fmt.Errorf("failed to decode: %s", err)
197 } 214 }
215
198 if data.Version != isolate.IsolatedGenJSONVersion { 216 if data.Version != isolate.IsolatedGenJSONVersion {
199 » » return nil, fmt.Errorf("invalid version %d in %s", data.Version, genJSONPath) 217 » » return nil, fmt.Errorf("invalid version %d", data.Version)
200 } 218 }
201 if !common.IsDirectory(data.Dir) { 219 if !common.IsDirectory(data.Dir) {
202 » » return nil, fmt.Errorf("invalid dir %s in %s", data.Dir, genJSON Path) 220 » » return nil, fmt.Errorf("invalid dir %s", data.Dir)
203 } 221 }
204 opts, err := parseArchiveCMD(data.Args, data.Dir) 222 opts, err := parseArchiveCMD(data.Args, data.Dir)
205 if err != nil { 223 if err != nil {
206 » » return nil, fmt.Errorf("invalid archive command in %s: %s", genJ SONPath, err) 224 » » return nil, fmt.Errorf("invalid archive command: %s", err)
207 } 225 }
208 return opts, nil 226 return opts, nil
209 } 227 }
210 228
211 // strippedIsolatedName returns the base name of an isolated path, with the exte nsion (if any) removed. 229 // strippedIsolatedName returns the base name of an isolated path, with the exte nsion (if any) removed.
212 func strippedIsolatedName(isolated string) string { 230 func strippedIsolatedName(isolated string) string {
213 name := filepath.Base(isolated) 231 name := filepath.Base(isolated)
214 // Strip the extension if there is one. 232 // Strip the extension if there is one.
215 if dotIndex := strings.LastIndex(name, "."); dotIndex != -1 { 233 if dotIndex := strings.LastIndex(name, "."); dotIndex != -1 {
216 return name[0:dotIndex] 234 return name[0:dotIndex]
(...skipping 11 matching lines...) Expand all
228 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) 246 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
229 return 1 247 return 1
230 } 248 }
231 defer cl.Close() 249 defer cl.Close()
232 if err := c.main(a, args); err != nil { 250 if err := c.main(a, args); err != nil {
233 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) 251 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err)
234 return 1 252 return 1
235 } 253 }
236 return 0 254 return 0
237 } 255 }
OLDNEW
« 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