Documentation ¶
Index ¶
- func MarshalWithSHA1(pm proto.Message) ([]byte, error)
- func UnmarshalWithSHA1(buf []byte, pm proto.Message) error
- type InstanceCache
- type TagCache
- func (c *TagCache) AddFile(ctx context.Context, pin common.Pin, fileName, hash string) error
- func (c *TagCache) AddTag(ctx context.Context, pin common.Pin, tag string) error
- func (c *TagCache) ResolveFile(ctx context.Context, pin common.Pin, fileName string) (hash string, err error)
- func (c *TagCache) ResolveTag(ctx context.Context, pkg, tag string) (pin common.Pin, err error)
- func (c *TagCache) Save(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalWithSHA1 ¶
MarshalWithSHA1 serializes proto message to bytes, calculates SHA1 checksum of it, and returns serialized envelope that contains both.
UnmarshalWithSHA1 can then be used to verify SHA1 and deserialized the original object.
Types ¶
type InstanceCache ¶
type InstanceCache struct {
// contains filtered or unexported fields
}
InstanceCache is a file-system-based, thread-safe, LRU cache of instances.
Does not validate instance hashes; it is caller's responsibility.
func NewInstanceCache ¶
func NewInstanceCache(fs local.FileSystem) *InstanceCache
NewInstanceCache initializes InstanceCache.
fs will be the root of the cache.
func (*InstanceCache) GC ¶
func (c *InstanceCache) GC(ctx context.Context, now time.Time)
GC opportunistically purges entries that haven't been touched for too long.
type TagCache ¶
type TagCache struct {
// contains filtered or unexported fields
}
TagCache provides a mapping (package name, tag) -> instance ID.
This mapping is safe to cache because tags are not detachable: once a tag is successfully resolved to an instance ID it is guaranteed to resolve to same instance ID later or not resolve at all (e.g. if one tag is attached to multiple instances, in which case the tag is misused anyway). In any case, returning a cached instance ID does make sense. The primary purpose of this cache is to avoid round trips to the service to increase reliability of 'cipd ensure' calls that use only tags to specify versions. It happens to be the most common case of 'cipd ensure' usage by far.
Additionally, this TagCache stores a mapping of (pin, file_name) -> hex(sha1(executable)) to assist in the `selfupdate` flow. Whenever selfupdate resolves what instance ID it SHOULD be at, it checks the SHA1 of its own binary to see if it's actually already at that instance ID (since instance ID is of the whole package, and not of the actual executable inside the package).
func NewTagCache ¶
func NewTagCache(fs local.FileSystem, service string) *TagCache
NewTagCache initializes TagCache.
fs will be the root of the cache. It will be searched for tagcache.db file.
func (*TagCache) AddFile ¶
AddFile records that (pin, fileName) maps to hash (where hash is the hex-encoded sha1 of the named file).
Call 'Save' later to persist these changes to the cache file on disk.
func (*TagCache) AddTag ¶
AddTag records that (pin.PackageName, tag) maps to pin.InstanceID.
Call 'Save' later to persist these changes to the cache file on disk.
func (*TagCache) ResolveFile ¶
func (c *TagCache) ResolveFile(ctx context.Context, pin common.Pin, fileName string) (hash string, err error)
ResolveFile returns file hash or "" if that file is not in the cache.
Returns error if the cache can't be read.
func (*TagCache) ResolveTag ¶
ResolveTag returns cached tag or empty Pin{} if such tag is not in the cache.
Returns error if the cache can't be read.