mirror of
https://github.com/containers/skopeo.git
synced 2025-09-14 13:59:44 +00:00
fix(deps): update github.com/containers/image/v5 digest to 58d5eb6
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
2
vendor/github.com/containers/image/v5/signature/sigstore/copied.go
generated
vendored
2
vendor/github.com/containers/image/v5/signature/sigstore/copied.go
generated
vendored
@@ -10,9 +10,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/secure-systems-lab/go-securesystemslib/encrypted"
|
||||
"github.com/sigstore/sigstore/pkg/cryptoutils"
|
||||
"github.com/sigstore/sigstore/pkg/signature"
|
||||
"github.com/theupdateframework/go-tuf/encrypted"
|
||||
)
|
||||
|
||||
// The following code was copied from github.com/sigstore.
|
||||
|
9
vendor/github.com/google/uuid/.travis.yml
generated
vendored
9
vendor/github.com/google/uuid/.travis.yml
generated
vendored
@@ -1,9 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.4.3
|
||||
- 1.5.3
|
||||
- tip
|
||||
|
||||
script:
|
||||
- go test -v ./...
|
10
vendor/github.com/google/uuid/CHANGELOG.md
generated
vendored
Normal file
10
vendor/github.com/google/uuid/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## [1.3.1](https://github.com/google/uuid/compare/v1.3.0...v1.3.1) (2023-08-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Use .EqualFold() to parse urn prefixed UUIDs ([#118](https://github.com/google/uuid/issues/118)) ([574e687](https://github.com/google/uuid/commit/574e6874943741fb99d41764c705173ada5293f0))
|
||||
|
||||
## Changelog
|
16
vendor/github.com/google/uuid/CONTRIBUTING.md
generated
vendored
16
vendor/github.com/google/uuid/CONTRIBUTING.md
generated
vendored
@@ -2,6 +2,22 @@
|
||||
|
||||
We definitely welcome patches and contribution to this project!
|
||||
|
||||
### Tips
|
||||
|
||||
Commits must be formatted according to the [Conventional Commits Specification](https://www.conventionalcommits.org).
|
||||
|
||||
Always try to include a test case! If it is not possible or not necessary,
|
||||
please explain why in the pull request description.
|
||||
|
||||
### Releasing
|
||||
|
||||
Commits that would precipitate a SemVer change, as desrcibed in the Conventional
|
||||
Commits Specification, will trigger [`release-please`](https://github.com/google-github-actions/release-please-action)
|
||||
to create a release candidate pull request. Once submitted, `release-please`
|
||||
will create a release.
|
||||
|
||||
For tips on how to work with `release-please`, see its documentation.
|
||||
|
||||
### Legal requirements
|
||||
|
||||
In order to protect both you and ourselves, you will need to sign the
|
||||
|
10
vendor/github.com/google/uuid/README.md
generated
vendored
10
vendor/github.com/google/uuid/README.md
generated
vendored
@@ -1,6 +1,6 @@
|
||||
# uuid 
|
||||
# uuid
|
||||
The uuid package generates and inspects UUIDs based on
|
||||
[RFC 4122](http://tools.ietf.org/html/rfc4122)
|
||||
[RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122)
|
||||
and DCE 1.1: Authentication and Security Services.
|
||||
|
||||
This package is based on the github.com/pborman/uuid package (previously named
|
||||
@@ -9,10 +9,12 @@ a UUID is a 16 byte array rather than a byte slice. One loss due to this
|
||||
change is the ability to represent an invalid UUID (vs a NIL UUID).
|
||||
|
||||
###### Install
|
||||
`go get github.com/google/uuid`
|
||||
```sh
|
||||
go get github.com/google/uuid
|
||||
```
|
||||
|
||||
###### Documentation
|
||||
[](http://godoc.org/github.com/google/uuid)
|
||||
[](https://pkg.go.dev/github.com/google/uuid)
|
||||
|
||||
Full `go doc` style documentation for the package can be viewed online without
|
||||
installing this package by using the GoDoc site here:
|
||||
|
2
vendor/github.com/google/uuid/node_js.go
generated
vendored
2
vendor/github.com/google/uuid/node_js.go
generated
vendored
@@ -7,6 +7,6 @@
|
||||
package uuid
|
||||
|
||||
// getHardwareInterface returns nil values for the JS version of the code.
|
||||
// This remvoves the "net" dependency, because it is not used in the browser.
|
||||
// This removes the "net" dependency, because it is not used in the browser.
|
||||
// Using the "net" library inflates the size of the transpiled JS code by 673k bytes.
|
||||
func getHardwareInterface(name string) (string, []byte) { return "", nil }
|
||||
|
10
vendor/github.com/google/uuid/uuid.go
generated
vendored
10
vendor/github.com/google/uuid/uuid.go
generated
vendored
@@ -69,7 +69,7 @@ func Parse(s string) (UUID, error) {
|
||||
|
||||
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
case 36 + 9:
|
||||
if strings.ToLower(s[:9]) != "urn:uuid:" {
|
||||
if !strings.EqualFold(s[:9], "urn:uuid:") {
|
||||
return uuid, fmt.Errorf("invalid urn prefix: %q", s[:9])
|
||||
}
|
||||
s = s[9:]
|
||||
@@ -101,7 +101,8 @@ func Parse(s string) (UUID, error) {
|
||||
9, 11,
|
||||
14, 16,
|
||||
19, 21,
|
||||
24, 26, 28, 30, 32, 34} {
|
||||
24, 26, 28, 30, 32, 34,
|
||||
} {
|
||||
v, ok := xtob(s[x], s[x+1])
|
||||
if !ok {
|
||||
return uuid, errors.New("invalid UUID format")
|
||||
@@ -117,7 +118,7 @@ func ParseBytes(b []byte) (UUID, error) {
|
||||
switch len(b) {
|
||||
case 36: // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
case 36 + 9: // urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
if !bytes.Equal(bytes.ToLower(b[:9]), []byte("urn:uuid:")) {
|
||||
if !bytes.EqualFold(b[:9], []byte("urn:uuid:")) {
|
||||
return uuid, fmt.Errorf("invalid urn prefix: %q", b[:9])
|
||||
}
|
||||
b = b[9:]
|
||||
@@ -145,7 +146,8 @@ func ParseBytes(b []byte) (UUID, error) {
|
||||
9, 11,
|
||||
14, 16,
|
||||
19, 21,
|
||||
24, 26, 28, 30, 32, 34} {
|
||||
24, 26, 28, 30, 32, 34,
|
||||
} {
|
||||
v, ok := xtob(b[x], b[x+1])
|
||||
if !ok {
|
||||
return uuid, errors.New("invalid UUID format")
|
||||
|
21
vendor/github.com/secure-systems-lab/go-securesystemslib/LICENSE
generated
vendored
Normal file
21
vendor/github.com/secure-systems-lab/go-securesystemslib/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2021 NYU Secure Systems Lab
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
290
vendor/github.com/secure-systems-lab/go-securesystemslib/encrypted/encrypted.go
generated
vendored
Normal file
290
vendor/github.com/secure-systems-lab/go-securesystemslib/encrypted/encrypted.go
generated
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
// Package encrypted provides a simple, secure system for encrypting data
|
||||
// symmetrically with a passphrase.
|
||||
//
|
||||
// It uses scrypt derive a key from the passphrase and the NaCl secret box
|
||||
// cipher for authenticated encryption.
|
||||
package encrypted
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/nacl/secretbox"
|
||||
"golang.org/x/crypto/scrypt"
|
||||
)
|
||||
|
||||
const saltSize = 32
|
||||
|
||||
const (
|
||||
boxKeySize = 32
|
||||
boxNonceSize = 24
|
||||
)
|
||||
|
||||
// KDFParameterStrength defines the KDF parameter strength level to be used for
|
||||
// encryption key derivation.
|
||||
type KDFParameterStrength uint8
|
||||
|
||||
const (
|
||||
// Legacy defines legacy scrypt parameters (N:2^15, r:8, p:1)
|
||||
Legacy KDFParameterStrength = iota + 1
|
||||
// Standard defines standard scrypt parameters which is focusing 100ms of computation (N:2^16, r:8, p:1)
|
||||
Standard
|
||||
// OWASP defines OWASP recommended scrypt parameters (N:2^17, r:8, p:1)
|
||||
OWASP
|
||||
)
|
||||
|
||||
var (
|
||||
// legacyParams represents old scrypt derivation parameters for backward
|
||||
// compatibility.
|
||||
legacyParams = scryptParams{
|
||||
N: 32768, // 2^15
|
||||
R: 8,
|
||||
P: 1,
|
||||
}
|
||||
|
||||
// standardParams defines scrypt parameters based on the scrypt creator
|
||||
// recommendation to limit key derivation in time boxed to 100ms.
|
||||
standardParams = scryptParams{
|
||||
N: 65536, // 2^16
|
||||
R: 8,
|
||||
P: 1,
|
||||
}
|
||||
|
||||
// owaspParams defines scrypt parameters recommended by OWASP
|
||||
owaspParams = scryptParams{
|
||||
N: 131072, // 2^17
|
||||
R: 8,
|
||||
P: 1,
|
||||
}
|
||||
|
||||
// defaultParams defines scrypt parameters which will be used to generate a
|
||||
// new key.
|
||||
defaultParams = standardParams
|
||||
)
|
||||
|
||||
const (
|
||||
nameScrypt = "scrypt"
|
||||
nameSecretBox = "nacl/secretbox"
|
||||
)
|
||||
|
||||
type data struct {
|
||||
KDF scryptKDF `json:"kdf"`
|
||||
Cipher secretBoxCipher `json:"cipher"`
|
||||
Ciphertext []byte `json:"ciphertext"`
|
||||
}
|
||||
|
||||
type scryptParams struct {
|
||||
N int `json:"N"`
|
||||
R int `json:"r"`
|
||||
P int `json:"p"`
|
||||
}
|
||||
|
||||
func (sp *scryptParams) Equal(in *scryptParams) bool {
|
||||
return in != nil && sp.N == in.N && sp.P == in.P && sp.R == in.R
|
||||
}
|
||||
|
||||
func newScryptKDF(level KDFParameterStrength) (scryptKDF, error) {
|
||||
salt := make([]byte, saltSize)
|
||||
if err := fillRandom(salt); err != nil {
|
||||
return scryptKDF{}, fmt.Errorf("unable to generate a random salt: %w", err)
|
||||
}
|
||||
|
||||
var params scryptParams
|
||||
switch level {
|
||||
case Legacy:
|
||||
params = legacyParams
|
||||
case Standard:
|
||||
params = standardParams
|
||||
case OWASP:
|
||||
params = owaspParams
|
||||
default:
|
||||
// Fallback to default parameters
|
||||
params = defaultParams
|
||||
}
|
||||
|
||||
return scryptKDF{
|
||||
Name: nameScrypt,
|
||||
Params: params,
|
||||
Salt: salt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type scryptKDF struct {
|
||||
Name string `json:"name"`
|
||||
Params scryptParams `json:"params"`
|
||||
Salt []byte `json:"salt"`
|
||||
}
|
||||
|
||||
func (s *scryptKDF) Key(passphrase []byte) ([]byte, error) {
|
||||
return scrypt.Key(passphrase, s.Salt, s.Params.N, s.Params.R, s.Params.P, boxKeySize)
|
||||
}
|
||||
|
||||
// CheckParams checks that the encoded KDF parameters are what we expect them to
|
||||
// be. If we do not do this, an attacker could cause a DoS by tampering with
|
||||
// them.
|
||||
func (s *scryptKDF) CheckParams() error {
|
||||
switch {
|
||||
case legacyParams.Equal(&s.Params):
|
||||
case standardParams.Equal(&s.Params):
|
||||
case owaspParams.Equal(&s.Params):
|
||||
default:
|
||||
return errors.New("unsupported scrypt parameters")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func newSecretBoxCipher() (secretBoxCipher, error) {
|
||||
nonce := make([]byte, boxNonceSize)
|
||||
if err := fillRandom(nonce); err != nil {
|
||||
return secretBoxCipher{}, err
|
||||
}
|
||||
return secretBoxCipher{
|
||||
Name: nameSecretBox,
|
||||
Nonce: nonce,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type secretBoxCipher struct {
|
||||
Name string `json:"name"`
|
||||
Nonce []byte `json:"nonce"`
|
||||
|
||||
encrypted bool
|
||||
}
|
||||
|
||||
func (s *secretBoxCipher) Encrypt(plaintext, key []byte) []byte {
|
||||
var keyBytes [boxKeySize]byte
|
||||
var nonceBytes [boxNonceSize]byte
|
||||
|
||||
if len(key) != len(keyBytes) {
|
||||
panic("incorrect key size")
|
||||
}
|
||||
if len(s.Nonce) != len(nonceBytes) {
|
||||
panic("incorrect nonce size")
|
||||
}
|
||||
|
||||
copy(keyBytes[:], key)
|
||||
copy(nonceBytes[:], s.Nonce)
|
||||
|
||||
// ensure that we don't re-use nonces
|
||||
if s.encrypted {
|
||||
panic("Encrypt must only be called once for each cipher instance")
|
||||
}
|
||||
s.encrypted = true
|
||||
|
||||
return secretbox.Seal(nil, plaintext, &nonceBytes, &keyBytes)
|
||||
}
|
||||
|
||||
func (s *secretBoxCipher) Decrypt(ciphertext, key []byte) ([]byte, error) {
|
||||
var keyBytes [boxKeySize]byte
|
||||
var nonceBytes [boxNonceSize]byte
|
||||
|
||||
if len(key) != len(keyBytes) {
|
||||
panic("incorrect key size")
|
||||
}
|
||||
if len(s.Nonce) != len(nonceBytes) {
|
||||
// return an error instead of panicking since the nonce is user input
|
||||
return nil, errors.New("encrypted: incorrect nonce size")
|
||||
}
|
||||
|
||||
copy(keyBytes[:], key)
|
||||
copy(nonceBytes[:], s.Nonce)
|
||||
|
||||
res, ok := secretbox.Open(nil, ciphertext, &nonceBytes, &keyBytes)
|
||||
if !ok {
|
||||
return nil, errors.New("encrypted: decryption failed")
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Encrypt takes a passphrase and plaintext, and returns a JSON object
|
||||
// containing ciphertext and the details necessary to decrypt it.
|
||||
func Encrypt(plaintext, passphrase []byte) ([]byte, error) {
|
||||
return EncryptWithCustomKDFParameters(plaintext, passphrase, Standard)
|
||||
}
|
||||
|
||||
// EncryptWithCustomKDFParameters takes a passphrase, the plaintext and a KDF
|
||||
// parameter level (Legacy, Standard, or OWASP), and returns a JSON object
|
||||
// containing ciphertext and the details necessary to decrypt it.
|
||||
func EncryptWithCustomKDFParameters(plaintext, passphrase []byte, kdfLevel KDFParameterStrength) ([]byte, error) {
|
||||
k, err := newScryptKDF(kdfLevel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
key, err := k.Key(passphrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c, err := newSecretBoxCipher()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := &data{
|
||||
KDF: k,
|
||||
Cipher: c,
|
||||
}
|
||||
data.Ciphertext = c.Encrypt(plaintext, key)
|
||||
|
||||
return json.Marshal(data)
|
||||
}
|
||||
|
||||
// Marshal encrypts the JSON encoding of v using passphrase.
|
||||
func Marshal(v interface{}, passphrase []byte) ([]byte, error) {
|
||||
return MarshalWithCustomKDFParameters(v, passphrase, Standard)
|
||||
}
|
||||
|
||||
// MarshalWithCustomKDFParameters encrypts the JSON encoding of v using passphrase.
|
||||
func MarshalWithCustomKDFParameters(v interface{}, passphrase []byte, kdfLevel KDFParameterStrength) ([]byte, error) {
|
||||
data, err := json.MarshalIndent(v, "", "\t")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return EncryptWithCustomKDFParameters(data, passphrase, kdfLevel)
|
||||
}
|
||||
|
||||
// Decrypt takes a JSON-encoded ciphertext object encrypted using Encrypt and
|
||||
// tries to decrypt it using passphrase. If successful, it returns the
|
||||
// plaintext.
|
||||
func Decrypt(ciphertext, passphrase []byte) ([]byte, error) {
|
||||
data := &data{}
|
||||
if err := json.Unmarshal(ciphertext, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if data.KDF.Name != nameScrypt {
|
||||
return nil, fmt.Errorf("encrypted: unknown kdf name %q", data.KDF.Name)
|
||||
}
|
||||
if data.Cipher.Name != nameSecretBox {
|
||||
return nil, fmt.Errorf("encrypted: unknown cipher name %q", data.Cipher.Name)
|
||||
}
|
||||
if err := data.KDF.CheckParams(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key, err := data.KDF.Key(passphrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data.Cipher.Decrypt(data.Ciphertext, key)
|
||||
}
|
||||
|
||||
// Unmarshal decrypts the data using passphrase and unmarshals the resulting
|
||||
// plaintext into the value pointed to by v.
|
||||
func Unmarshal(data []byte, v interface{}, passphrase []byte) error {
|
||||
decrypted, err := Decrypt(data, passphrase)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal(decrypted, v)
|
||||
}
|
||||
|
||||
func fillRandom(b []byte) error {
|
||||
_, err := io.ReadFull(rand.Reader, b)
|
||||
return err
|
||||
}
|
1
vendor/github.com/sylabs/sif/v2/pkg/sif/descriptor_input.go
generated
vendored
1
vendor/github.com/sylabs/sif/v2/pkg/sif/descriptor_input.go
generated
vendored
@@ -111,7 +111,6 @@ func (e *unexpectedDataTypeError) Error() string {
|
||||
}
|
||||
|
||||
func (e *unexpectedDataTypeError) Is(target error) bool {
|
||||
//nolint:errorlint // don't compare wrapped errors in Is()
|
||||
t, ok := target.(*unexpectedDataTypeError)
|
||||
if !ok {
|
||||
return false
|
||||
|
15
vendor/github.com/vbauerster/mpb/v8/CONTRIBUTING
generated
vendored
Normal file
15
vendor/github.com/vbauerster/mpb/v8/CONTRIBUTING
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
When contributing your first changes, please include an empty commit for
|
||||
copyright waiver using the following message (replace 'John Doe' with
|
||||
your name or nickname):
|
||||
|
||||
John Doe Copyright Waiver
|
||||
|
||||
I dedicate any and all copyright interest in this software to the
|
||||
public domain. I make this dedication for the benefit of the public at
|
||||
large and to the detriment of my heirs and successors. I intend this
|
||||
dedication to be an overt act of relinquishment in perpetuity of all
|
||||
present and future rights to this software under copyright law.
|
||||
|
||||
The command to create an empty commit from the command-line is:
|
||||
|
||||
git commit --allow-empty
|
2
vendor/github.com/vbauerster/mpb/v8/bar.go
generated
vendored
2
vendor/github.com/vbauerster/mpb/v8/bar.go
generated
vendored
@@ -338,7 +338,7 @@ func (b *Bar) DecoratorAverageAdjust(start time.Time) {
|
||||
// priority, i.e. bar will be on top. If you don't need to set priority
|
||||
// dynamically, better use BarPriority option.
|
||||
func (b *Bar) SetPriority(priority int) {
|
||||
b.container.UpdateBarPriority(b, priority)
|
||||
b.container.UpdateBarPriority(b, priority, false)
|
||||
}
|
||||
|
||||
// Abort interrupts bar's running goroutine. Abort won't be engaged
|
||||
|
21
vendor/github.com/vbauerster/mpb/v8/decor/on_compete_or_on_abort.go
generated
vendored
Normal file
21
vendor/github.com/vbauerster/mpb/v8/decor/on_compete_or_on_abort.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
package decor
|
||||
|
||||
// OnCompleteOrOnAbort wrap decorator.
|
||||
// Displays provided message on complete or on abort event.
|
||||
//
|
||||
// `decorator` Decorator to wrap
|
||||
// `message` message to display
|
||||
func OnCompleteOrOnAbort(decorator Decorator, message string) Decorator {
|
||||
return OnComplete(OnAbort(decorator, message), message)
|
||||
}
|
||||
|
||||
// OnCompleteMetaOrOnAbortMeta wrap decorator.
|
||||
// Provided fn is supposed to wrap output of given decorator
|
||||
// with meta information like ANSI escape codes for example.
|
||||
// Primary usage intention is to set SGR display attributes.
|
||||
//
|
||||
// `decorator` Decorator to wrap
|
||||
// `fn` func to apply meta information
|
||||
func OnCompleteMetaOrOnAbortMeta(decorator Decorator, fn func(string) string) Decorator {
|
||||
return OnCompleteMeta(OnAbortMeta(decorator, fn), fn)
|
||||
}
|
27
vendor/github.com/vbauerster/mpb/v8/heap_manager.go
generated
vendored
27
vendor/github.com/vbauerster/mpb/v8/heap_manager.go
generated
vendored
@@ -1,8 +1,6 @@
|
||||
package mpb
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
)
|
||||
import "container/heap"
|
||||
|
||||
type heapManager chan heapRequest
|
||||
|
||||
@@ -36,6 +34,7 @@ type pushData struct {
|
||||
type fixData struct {
|
||||
bar *Bar
|
||||
priority int
|
||||
lazy bool
|
||||
}
|
||||
|
||||
func (m heapManager) run() {
|
||||
@@ -46,7 +45,6 @@ func (m heapManager) run() {
|
||||
var sync bool
|
||||
|
||||
for req := range m {
|
||||
next:
|
||||
switch req.cmd {
|
||||
case h_push:
|
||||
data := req.data.(pushData)
|
||||
@@ -75,34 +73,35 @@ func (m heapManager) run() {
|
||||
syncWidth(aMatrix, drop)
|
||||
case h_iter:
|
||||
data := req.data.(iterData)
|
||||
drop_iter:
|
||||
for _, b := range bHeap {
|
||||
select {
|
||||
case data.iter <- b:
|
||||
case <-data.drop:
|
||||
close(data.iter)
|
||||
break next
|
||||
break drop_iter
|
||||
}
|
||||
}
|
||||
close(data.iter)
|
||||
case h_drain:
|
||||
data := req.data.(iterData)
|
||||
drop_drain:
|
||||
for bHeap.Len() != 0 {
|
||||
select {
|
||||
case data.iter <- heap.Pop(&bHeap).(*Bar):
|
||||
case <-data.drop:
|
||||
close(data.iter)
|
||||
break next
|
||||
break drop_drain
|
||||
}
|
||||
}
|
||||
close(data.iter)
|
||||
case h_fix:
|
||||
data := req.data.(fixData)
|
||||
bar, priority := data.bar, data.priority
|
||||
if bar.index < 0 {
|
||||
if data.bar.index < 0 {
|
||||
break
|
||||
}
|
||||
bar.priority = priority
|
||||
heap.Fix(&bHeap, bar.index)
|
||||
data.bar.priority = data.priority
|
||||
if !data.lazy {
|
||||
heap.Fix(&bHeap, data.bar.index)
|
||||
}
|
||||
case h_state:
|
||||
ch := req.data.(chan<- bool)
|
||||
ch <- sync || l != bHeap.Len()
|
||||
@@ -137,8 +136,8 @@ func (m heapManager) drain(iter chan<- *Bar, drop <-chan struct{}) {
|
||||
m <- heapRequest{cmd: h_drain, data: data}
|
||||
}
|
||||
|
||||
func (m heapManager) fix(b *Bar, priority int) {
|
||||
data := fixData{b, priority}
|
||||
func (m heapManager) fix(b *Bar, priority int, lazy bool) {
|
||||
data := fixData{b, priority, lazy}
|
||||
m <- heapRequest{cmd: h_fix, data: data}
|
||||
}
|
||||
|
||||
|
15
vendor/github.com/vbauerster/mpb/v8/priority_queue.go
generated
vendored
15
vendor/github.com/vbauerster/mpb/v8/priority_queue.go
generated
vendored
@@ -20,17 +20,18 @@ func (pq priorityQueue) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) Push(x interface{}) {
|
||||
s := *pq
|
||||
n := len(*pq)
|
||||
bar := x.(*Bar)
|
||||
bar.index = len(s)
|
||||
s = append(s, bar)
|
||||
*pq = s
|
||||
bar.index = n
|
||||
*pq = append(*pq, bar)
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) Pop() interface{} {
|
||||
s := *pq
|
||||
*pq = s[0 : len(s)-1]
|
||||
bar := s[len(s)-1]
|
||||
old := *pq
|
||||
n := len(old)
|
||||
bar := old[n-1]
|
||||
old[n-1] = nil // avoid memory leak
|
||||
bar.index = -1 // for safety
|
||||
*pq = old[:n-1]
|
||||
return bar
|
||||
}
|
||||
|
11
vendor/github.com/vbauerster/mpb/v8/progress.go
generated
vendored
11
vendor/github.com/vbauerster/mpb/v8/progress.go
generated
vendored
@@ -201,10 +201,15 @@ func (p *Progress) traverseBars(cb func(b *Bar) bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateBarPriority same as *Bar.SetPriority(int).
|
||||
func (p *Progress) UpdateBarPriority(b *Bar, priority int) {
|
||||
// UpdateBarPriority either immediately or lazy.
|
||||
// With lazy flag order is updated after the next refresh cycle.
|
||||
// If you don't care about laziness just use *Bar.SetPriority(int).
|
||||
func (p *Progress) UpdateBarPriority(b *Bar, priority int, lazy bool) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case p.operateState <- func(s *pState) { s.hm.fix(b, priority) }:
|
||||
case p.operateState <- func(s *pState) { s.hm.fix(b, priority, lazy) }:
|
||||
case <-p.done:
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user