Update c/image from the main branch

> go get github.com/containers/image/v5@main
> make vendor

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2023-04-01 12:19:48 +02:00
parent 4f475bd4d2
commit bfe82593c8
285 changed files with 21881 additions and 4003 deletions

View File

@@ -41,8 +41,9 @@ type bState struct {
completed bool
aborted bool
triggerComplete bool
dropOnComplete bool
rmOnComplete bool
noPop bool
autoRefresh bool
aDecorators []decor.Decorator
pDecorators []decor.Decorator
averageDecorators []decor.AverageDecorator
@@ -50,24 +51,22 @@ type bState struct {
shutdownListeners []decor.ShutdownListener
buffers [3]*bytes.Buffer
filler BarFiller
middleware func(BarFiller) BarFiller
extender extenderFunc
manualRefresh chan interface{}
wait struct {
bar *Bar // key for (*pState).queueBars
sync bool
}
renderReq chan<- time.Time
waitBar *Bar // key for (*pState).queueBars
}
type renderFrame struct {
rows []io.Reader
shutdown bool
err error
rows []io.Reader
shutdown int
rmOnComplete bool
noPop bool
done bool
err error
}
func newBar(container *Progress, bs *bState) *Bar {
ctx, cancel := context.WithCancel(container.ctx)
func newBar(ctx context.Context, container *Progress, bs *bState) *Bar {
ctx, cancel := context.WithCancel(ctx)
bar := &Bar{
priority: bs.priority,
@@ -78,6 +77,7 @@ func newBar(container *Progress, bs *bState) *Bar {
cancel: cancel,
}
container.bwg.Add(1)
go bar.serve(ctx, bs)
return bar
}
@@ -144,29 +144,29 @@ func (b *Bar) Current() int64 {
// operation for example.
func (b *Bar) SetRefill(amount int64) {
select {
case b.operateState <- func(s *bState) {
s.refill = amount
}:
case b.operateState <- func(s *bState) { s.refill = amount }:
case <-b.done:
}
}
// TraverseDecorators traverses all available decorators and calls cb func on each.
func (b *Bar) TraverseDecorators(cb func(decor.Decorator)) {
sync := make(chan struct{})
iter := make(chan decor.Decorator)
select {
case b.operateState <- func(s *bState) {
defer close(sync)
for _, decorators := range [][]decor.Decorator{
s.pDecorators,
s.aDecorators,
} {
for _, d := range decorators {
cb(extractBaseDecorator(d))
iter <- d
}
}
close(iter)
}:
<-sync
for d := range iter {
cb(unwrap(d))
}
case <-b.done:
}
}
@@ -185,7 +185,7 @@ func (b *Bar) EnableTriggerComplete() {
if s.current >= s.total {
s.current = s.total
s.completed = true
b.forceRefresh(s.manualRefresh)
b.triggerCompletion(s)
} else {
s.triggerComplete = true
}
@@ -197,9 +197,9 @@ func (b *Bar) EnableTriggerComplete() {
// SetTotal sets total to an arbitrary value. It's effective only for
// bar which was constructed with `total <= 0`. Setting total to negative
// value is equivalent to (*Bar).SetTotal((*Bar).Current(), bool) but faster.
// If triggerCompleteNow is true, total value is set to current and
// If triggerCompletion is true, total value is set to current and
// complete event is triggered right away.
func (b *Bar) SetTotal(total int64, triggerCompleteNow bool) {
func (b *Bar) SetTotal(total int64, triggerCompletion bool) {
select {
case b.operateState <- func(s *bState) {
if s.triggerComplete {
@@ -210,10 +210,10 @@ func (b *Bar) SetTotal(total int64, triggerCompleteNow bool) {
} else {
s.total = total
}
if triggerCompleteNow {
if triggerCompletion {
s.current = s.total
s.completed = true
b.forceRefresh(s.manualRefresh)
b.triggerCompletion(s)
}
}:
case <-b.done:
@@ -231,7 +231,7 @@ func (b *Bar) SetCurrent(current int64) {
if s.triggerComplete && s.current >= s.total {
s.current = s.total
s.completed = true
b.forceRefresh(s.manualRefresh)
b.triggerCompletion(s)
}
}:
case <-b.done:
@@ -247,13 +247,13 @@ func (b *Bar) EwmaSetCurrent(current int64, iterDur time.Duration) {
select {
case b.operateState <- func(s *bState) {
if n := current - s.current; n > 0 {
s.ewmaUpdate(n, iterDur)
s.decoratorEwmaUpdate(n, iterDur)
}
s.current = current
if s.triggerComplete && s.current >= s.total {
s.current = s.total
s.completed = true
b.forceRefresh(s.manualRefresh)
b.triggerCompletion(s)
}
}:
case <-b.done:
@@ -281,7 +281,7 @@ func (b *Bar) IncrInt64(n int64) {
if s.triggerComplete && s.current >= s.total {
s.current = s.total
s.completed = true
b.forceRefresh(s.manualRefresh)
b.triggerCompletion(s)
}
}:
case <-b.done:
@@ -306,12 +306,12 @@ func (b *Bar) EwmaIncrInt64(n int64, iterDur time.Duration) {
}
select {
case b.operateState <- func(s *bState) {
s.ewmaUpdate(n, iterDur)
s.decoratorEwmaUpdate(n, iterDur)
s.current += n
if s.triggerComplete && s.current >= s.total {
s.current = s.total
s.completed = true
b.forceRefresh(s.manualRefresh)
b.triggerCompletion(s)
}
}:
case <-b.done:
@@ -323,9 +323,7 @@ func (b *Bar) EwmaIncrInt64(n int64, iterDur time.Duration) {
// or after progress resume.
func (b *Bar) DecoratorAverageAdjust(start time.Time) {
select {
case b.operateState <- func(s *bState) {
s.decoratorAverageAdjust(start)
}:
case b.operateState <- func(s *bState) { s.decoratorAverageAdjust(start) }:
case <-b.done:
}
}
@@ -348,8 +346,8 @@ func (b *Bar) Abort(drop bool) {
return
}
s.aborted = true
s.dropOnComplete = drop
b.forceRefresh(s.manualRefresh)
s.rmOnComplete = drop
b.triggerCompletion(s)
}:
case <-b.done:
}
@@ -382,9 +380,7 @@ func (b *Bar) Completed() bool {
func (b *Bar) IsRunning() bool {
result := make(chan bool)
select {
case b.operateState <- func(s *bState) {
result <- !s.completed && !s.aborted
}:
case b.operateState <- func(s *bState) { result <- !s.completed && !s.aborted }:
return <-result
case <-b.done:
return false
@@ -398,9 +394,6 @@ func (b *Bar) Wait() {
func (b *Bar) serve(ctx context.Context, bs *bState) {
defer b.container.bwg.Done()
if bs.wait.bar != nil && bs.wait.sync {
bs.wait.bar.Wait()
}
for {
select {
case op := <-b.operateState:
@@ -433,10 +426,16 @@ func (b *Bar) render(tw int) {
return
}
}
frame := &renderFrame{rows: rows}
frame := &renderFrame{
rows: rows,
shutdown: s.shutdown,
rmOnComplete: s.rmOnComplete,
noPop: s.noPop,
done: done,
}
if s.completed || s.aborted {
frame.shutdown = !done || s.shutdown == 1
b.cancel()
// post increment makes sure OnComplete decorators are rendered
s.shutdown++
}
b.frameCh <- frame
}
@@ -448,22 +447,27 @@ func (b *Bar) render(tw int) {
}
}
func (b *Bar) forceRefresh(refreshCh chan interface{}) {
b.container.bwg.Add(1)
go b.forceRefreshImpl(refreshCh)
func (b *Bar) triggerCompletion(s *bState) {
if s.autoRefresh {
// Technically this call isn't required, but if refresh rate is set to
// one hour for example and bar completes within a few minutes p.Wait()
// will wait for one hour. This call helps to avoid unnecessary waiting.
go b.tryEarlyRefresh(s.renderReq)
} else {
b.cancel()
}
}
func (b *Bar) forceRefreshImpl(refreshCh chan interface{}) {
defer b.container.bwg.Done()
func (b *Bar) tryEarlyRefresh(renderReq chan<- time.Time) {
var anyOtherRunning bool
b.container.traverseBars(func(bar *Bar) bool {
anyOtherRunning = b != bar && bar.IsRunning()
return !anyOtherRunning
return anyOtherRunning
})
if !anyOtherRunning {
for {
select {
case refreshCh <- time.Now():
case renderReq <- time.Now():
case <-b.done:
return
}
@@ -584,27 +588,7 @@ func (s *bState) wSyncTable() (table syncTable) {
return table
}
func (s *bState) subscribeDecorators() {
for _, decorators := range [][]decor.Decorator{
s.pDecorators,
s.aDecorators,
} {
for _, d := range decorators {
d = extractBaseDecorator(d)
if d, ok := d.(decor.AverageDecorator); ok {
s.averageDecorators = append(s.averageDecorators, d)
}
if d, ok := d.(decor.EwmaDecorator); ok {
s.ewmaDecorators = append(s.ewmaDecorators, d)
}
if d, ok := d.(decor.ShutdownListener); ok {
s.shutdownListeners = append(s.shutdownListeners, d)
}
}
}
}
func (s bState) ewmaUpdate(n int64, dur time.Duration) {
func (s bState) decoratorEwmaUpdate(n int64, dur time.Duration) {
var wg sync.WaitGroup
for i := 0; i < len(s.ewmaDecorators); i++ {
switch d := s.ewmaDecorators[i]; i {
@@ -643,11 +627,11 @@ func (s bState) decoratorShutdownNotify() {
for i := 0; i < len(s.shutdownListeners); i++ {
switch d := s.shutdownListeners[i]; i {
case len(s.shutdownListeners) - 1:
d.Shutdown()
d.OnShutdown()
default:
wg.Add(1)
go func() {
d.Shutdown()
d.OnShutdown()
wg.Done()
}()
}
@@ -668,9 +652,9 @@ func newStatistics(tw int, s *bState) decor.Statistics {
}
}
func extractBaseDecorator(d decor.Decorator) decor.Decorator {
func unwrap(d decor.Decorator) decor.Decorator {
if d, ok := d.(decor.Wrapper); ok {
return extractBaseDecorator(d.Base())
return unwrap(d.Unwrap())
}
return d
}