| OLD | NEW |
| 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 "encoding/json" |
| 9 "errors" | 9 "errors" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 func cmdExpArchive(defaultAuthOpts auth.Options) *subcommands.Command { | 44 func cmdExpArchive(defaultAuthOpts auth.Options) *subcommands.Command { |
| 45 return &subcommands.Command{ | 45 return &subcommands.Command{ |
| 46 UsageLine: "exparchive <options>", | 46 UsageLine: "exparchive <options>", |
| 47 ShortDesc: "EXPERIMENTAL parses a .isolate file to create a .iso
lated file, and uploads it and all referenced files to an isolate server", | 47 ShortDesc: "EXPERIMENTAL parses a .isolate file to create a .iso
lated file, and uploads it and all referenced files to an isolate server", |
| 48 LongDesc: "All the files listed in the .isolated file are put i
n the isolate server cache. Small files are combined together in a tar archive b
efore uploading.", | 48 LongDesc: "All the files listed in the .isolated file are put i
n the isolate server cache. Small files are combined together in a tar archive b
efore uploading.", |
| 49 CommandRun: func() subcommands.CommandRun { | 49 CommandRun: func() subcommands.CommandRun { |
| 50 c := &expArchiveRun{} | 50 c := &expArchiveRun{} |
| 51 c.commonServerFlags.Init(defaultAuthOpts) | 51 c.commonServerFlags.Init(defaultAuthOpts) |
| 52 c.isolateFlags.Init(&c.Flags) | 52 c.isolateFlags.Init(&c.Flags) |
| 53 c.loggingFlags.Init(&c.Flags) |
| 53 c.Flags.StringVar(&c.dumpJSON, "dump-json", "", | 54 c.Flags.StringVar(&c.dumpJSON, "dump-json", "", |
| 54 "Write isolated digests of archived trees to thi
s file as JSON") | 55 "Write isolated digests of archived trees to thi
s file as JSON") |
| 55 return c | 56 return c |
| 56 }, | 57 }, |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 // expArchiveRun contains the logic for the experimental archive subcommand. | 61 // expArchiveRun contains the logic for the experimental archive subcommand. |
| 61 // It implements subcommand.CommandRun | 62 // It implements subcommand.CommandRun |
| 62 type expArchiveRun struct { | 63 type expArchiveRun struct { |
| 63 commonServerFlags // Provides the GetFlags method. | 64 commonServerFlags // Provides the GetFlags method. |
| 64 isolateFlags isolateFlags | 65 isolateFlags isolateFlags |
| 66 loggingFlags loggingFlags |
| 65 dumpJSON string | 67 dumpJSON string |
| 66 } | 68 } |
| 67 | 69 |
| 68 // Item represents a file or symlink referenced by an isolate file. | 70 // Item represents a file or symlink referenced by an isolate file. |
| 69 type Item struct { | 71 type Item struct { |
| 70 Path string | 72 Path string |
| 71 RelPath string | 73 RelPath string |
| 72 Size int64 | 74 Size int64 |
| 73 Mode os.FileMode | 75 Mode os.FileMode |
| 74 | 76 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 281 |
| 280 end := time.Now() | 282 end := time.Now() |
| 281 | 283 |
| 282 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{ | 284 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{ |
| 283 HitCount: proto.Int64(int64(checker.Hit.Count)), | 285 HitCount: proto.Int64(int64(checker.Hit.Count)), |
| 284 MissCount: proto.Int64(int64(checker.Miss.Count)), | 286 MissCount: proto.Int64(int64(checker.Miss.Count)), |
| 285 HitBytes: &checker.Hit.Bytes, | 287 HitBytes: &checker.Hit.Bytes, |
| 286 MissBytes: &checker.Miss.Bytes, | 288 MissBytes: &checker.Miss.Bytes, |
| 287 IsolateHash: []string{string(isolItem.Digest)}, | 289 IsolateHash: []string{string(isolItem.Digest)}, |
| 288 } | 290 } |
| 289 » eventlogger := NewLogger(ctx, c.isolateFlags.EventlogEndpoint) | 291 » eventlogger := NewLogger(ctx, c.loggingFlags.EventlogEndpoint) |
| 290 op := logpb.IsolateClientEvent_ARCHIVE.Enum() | 292 op := logpb.IsolateClientEvent_ARCHIVE.Enum() |
| 291 if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err
!= nil { | 293 if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err
!= nil { |
| 292 log.Printf("Failed to log to eventlog: %v", err) | 294 log.Printf("Failed to log to eventlog: %v", err) |
| 293 } | 295 } |
| 294 | 296 |
| 295 return nil | 297 return nil |
| 296 } | 298 } |
| 297 | 299 |
| 298 func (c *expArchiveRun) parseFlags(args []string) error { | 300 func (c *expArchiveRun) parseFlags(args []string) error { |
| 299 if len(args) != 0 { | 301 if len(args) != 0 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 330 } | 332 } |
| 331 | 333 |
| 332 func hashFile(path string) (isolated.HexDigest, error) { | 334 func hashFile(path string) (isolated.HexDigest, error) { |
| 333 f, err := os.Open(path) | 335 f, err := os.Open(path) |
| 334 if err != nil { | 336 if err != nil { |
| 335 return "", err | 337 return "", err |
| 336 } | 338 } |
| 337 defer f.Close() | 339 defer f.Close() |
| 338 return isolated.Hash(f) | 340 return isolated.Hash(f) |
| 339 } | 341 } |
| OLD | NEW |