本文整理匯總了Golang中github.com/coreos/rkt/store/imagestore.Store.HashToKey方法的典型用法代碼示例。如果您正苦於以下問題:Golang Store.HashToKey方法的具體用法?Golang Store.HashToKey怎麽用?Golang Store.HashToKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/rkt/store/imagestore.Store
的用法示例。
在下文中一共展示了Store.HashToKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getTmpROC
// getTmpROC returns a removeOnClose instance wrapping a temporary
// file provided by the passed store. The actual file name is based on
// a hash of the passed path.
func getTmpROC(s *imagestore.Store, path string) (*removeOnClose, error) {
h := sha512.New()
h.Write([]byte(path))
pathHash := s.HashToKey(h)
tmp, err := s.TmpNamedFile(pathHash)
if err != nil {
return nil, errwrap.Wrap(errors.New("error setting up temporary file"), err)
}
// let's lock the file to avoid concurrent writes to the temporary file, it
// will go away when removing the temp file
_, err = lock.TryExclusiveLock(tmp.Name(), lock.RegFile)
if err != nil {
if err != lock.ErrLocked {
return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err)
}
log.Printf("another rkt instance is downloading this file, waiting...")
_, err = lock.ExclusiveLock(tmp.Name(), lock.RegFile)
if err != nil {
return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err)
}
}
return &removeOnClose{File: tmp}, nil
}