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

Side by Side Diff: go/src/infra/tools/cipd/local/reader.go

Issue 1129043003: cipd: Refactor client to make it more readable. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package cipd 5 package local
6 6
7 import ( 7 import (
8 "archive/zip" 8 "archive/zip"
9 "crypto/sha1" 9 "crypto/sha1"
10 "encoding/hex" 10 "encoding/hex"
11 "fmt" 11 "fmt"
12 "io" 12 "io"
13 "io/ioutil" 13 "io/ioutil"
14 "os" 14 "os"
15
16 "infra/tools/cipd/common"
15 ) 17 )
16 18
17 // PackageInstance represents a binary package file. 19 // PackageInstance represents a binary package file.
18 type PackageInstance interface { 20 type PackageInstance interface {
19 // Close shuts down the package and its data provider. 21 // Close shuts down the package and its data provider.
20 Close() error 22 Close() error
21 » // PackageName returns package name, as defined in the manifest. 23 » // Pin identifies package name and concreted package instance ID of this package file.
22 » PackageName() string 24 » Pin() common.Pin
23 » // InstanceID returns id that identifies particular built of the package . It's a hash of the package data.
24 » InstanceID() string
25 // Files returns a list of files inside the package. 25 // Files returns a list of files inside the package.
26 Files() []File 26 Files() []File
27 // DataReader returns reader that reads raw package data. 27 // DataReader returns reader that reads raw package data.
28 DataReader() io.ReadSeeker 28 DataReader() io.ReadSeeker
29 } 29 }
30 30
31 // OpenInstance verifies package SHA1 hash (instanceID if not empty string) and 31 // OpenInstance verifies package SHA1 hash (instanceID if not empty string) and
32 // prepares a package instance for extraction. If the call succeeds, 32 // prepares a package instance for extraction. If the call succeeds,
33 // PackageInstance takes ownership of io.ReadSeeker. If it also implements 33 // PackageInstance takes ownership of io.ReadSeeker. If it also implements
34 // io.Closer, it will be closed when package.Close() is called. If an error is 34 // io.Closer, it will be closed when package.Close() is called. If an error is
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 inst.data = nil 179 inst.data = nil
180 } 180 }
181 inst.dataSize = 0 181 inst.dataSize = 0
182 inst.instanceID = "" 182 inst.instanceID = ""
183 inst.zip = nil 183 inst.zip = nil
184 inst.files = []File{} 184 inst.files = []File{}
185 inst.manifest = Manifest{} 185 inst.manifest = Manifest{}
186 return nil 186 return nil
187 } 187 }
188 188
189 func (inst *packageInstance) InstanceID() string { return inst.instanceID } 189 func (inst *packageInstance) Pin() common.Pin {
190 func (inst *packageInstance) PackageName() string { return inst.manifest.P ackageName } 190 » return common.Pin{
191 » » PackageName: inst.manifest.PackageName,
192 » » InstanceID: inst.instanceID,
193 » }
194 }
195
191 func (inst *packageInstance) Files() []File { return inst.files } 196 func (inst *packageInstance) Files() []File { return inst.files }
192 func (inst *packageInstance) DataReader() io.ReadSeeker { return inst.data } 197 func (inst *packageInstance) DataReader() io.ReadSeeker { return inst.data }
193 198
194 //////////////////////////////////////////////////////////////////////////////// 199 ////////////////////////////////////////////////////////////////////////////////
195 // Utilities. 200 // Utilities.
196 201
197 // readManifestFile decodes manifest file zipped inside the package. 202 // readManifestFile decodes manifest file zipped inside the package.
198 func readManifestFile(f File) (Manifest, error) { 203 func readManifestFile(f File) (Manifest, error) {
199 r, err := f.Open() 204 r, err := f.Open()
200 if err != nil { 205 if err != nil {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 r io.ReadSeeker 265 r io.ReadSeeker
261 } 266 }
262 267
263 func (r *readerAt) ReadAt(data []byte, off int64) (int, error) { 268 func (r *readerAt) ReadAt(data []byte, off int64) (int, error) {
264 _, err := r.r.Seek(off, os.SEEK_SET) 269 _, err := r.r.Seek(off, os.SEEK_SET)
265 if err != nil { 270 if err != nil {
266 return 0, err 271 return 0, err
267 } 272 }
268 return r.r.Read(data) 273 return r.r.Read(data)
269 } 274 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/local/pkgdef_test.go ('k') | go/src/infra/tools/cipd/local/reader_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698