MCPcopy
hub / github.com/containerd/containerd / withLease

Method withLease

core/transfer/local/transfer.go:138–168  ·  view source on GitHub ↗

WithLease attaches a lease on the context

(ctx context.Context, opts ...leases.Opt)

Source from the content-addressed store, hash-verified

136
137// WithLease attaches a lease on the context
138func (ts *localTransferService) withLease(ctx context.Context, opts ...leases.Opt) (context.Context, func(context.Context) error, error) {
139 nop := func(context.Context) error { return nil }
140
141 _, ok := leases.FromContext(ctx)
142 if ok {
143 return ctx, nop, nil
144 }
145
146 ls := ts.config.Leases
147 if ls == nil {
148 return ctx, nop, nil
149 }
150
151 if len(opts) == 0 {
152 // Use default lease configuration if no options provided
153 opts = []leases.Opt{
154 leases.WithRandomID(),
155 leases.WithExpiration(24 * time.Hour),
156 }
157 }
158
159 l, err := ls.Create(ctx, opts...)
160 if err != nil {
161 return ctx, nop, err
162 }
163
164 ctx = leases.WithLease(ctx, l.ID)
165 return ctx, func(ctx context.Context) error {
166 return ls.Delete(ctx, l)
167 }, nil
168}
169
170type TransferConfig struct {
171 // Leases manager is used to create leases during operations if none, exists

Callers 4

exportStreamMethod · 0.95
pullMethod · 0.95
importStreamMethod · 0.95
tagMethod · 0.95

Calls 6

FromContextFunction · 0.92
WithRandomIDFunction · 0.92
WithExpirationFunction · 0.92
WithLeaseFunction · 0.92
CreateMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected