本文整理汇总了Golang中github.com/luci/luci-go/common/isolated.HexDigest.Validate方法的典型用法代码示例。如果您正苦于以下问题:Golang HexDigest.Validate方法的具体用法?Golang HexDigest.Validate怎么用?Golang HexDigest.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/luci/luci-go/common/isolated.HexDigest
的用法示例。
在下文中一共展示了HexDigest.Validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Add
func (d *disk) Add(digest isolated.HexDigest, src io.Reader) error {
if !digest.Validate() {
return os.ErrInvalid
}
p := d.itemPath(digest)
dst, err := os.Create(p)
if err != nil {
return err
}
h := isolated.GetHash()
// TODO(maruel): Use a LimitedReader flavor that fails when reaching limit.
size, err := io.Copy(dst, io.TeeReader(src, h))
if err2 := dst.Close(); err == nil {
err = err2
}
if err != nil {
_ = os.Remove(p)
return err
}
if isolated.Sum(h) != digest {
_ = os.Remove(p)
return errors.New("invalid hash")
}
if common.Size(size) > d.policies.MaxSize {
_ = os.Remove(p)
return errors.New("item too large")
}
d.lock.Lock()
defer d.lock.Unlock()
d.lru.pushFront(digest, common.Size(size))
d.respectPolicies()
return nil
}
示例2: Evict
func (m *memory) Evict(digest isolated.HexDigest) {
if !digest.Validate() {
return
}
m.lock.Lock()
defer m.lock.Unlock()
delete(m.data, digest)
m.lru.pop(digest)
}
示例3: Read
func (d *disk) Read(digest isolated.HexDigest) (io.ReadCloser, error) {
if !digest.Validate() {
return nil, os.ErrInvalid
}
f, err := os.Open(d.itemPath(digest))
if err != nil {
return nil, err
}
return f, nil
}
示例4: Hardlink
func (m *memory) Hardlink(digest isolated.HexDigest, dest string, perm os.FileMode) error {
if !digest.Validate() {
return os.ErrInvalid
}
m.lock.Lock()
content, ok := m.data[digest]
m.lock.Unlock()
if !ok {
return os.ErrNotExist
}
return ioutil.WriteFile(dest, content, perm)
}
示例5: Touch
func (m *memory) Touch(digest isolated.HexDigest) bool {
if !digest.Validate() {
return false
}
m.lock.Lock()
defer m.lock.Unlock()
if _, ok := m.data[digest]; !ok {
return false
}
m.lru.touch(digest)
return true
}