(ic *plugin.InitContext, uc unpackConfiguration, p specs.Platform)
| 165 | } |
| 166 | |
| 167 | func getApplier(ic *plugin.InitContext, uc unpackConfiguration, p specs.Platform) (diff.Applier, bool, error) { |
| 168 | if uc.Differ != "" { |
| 169 | inst, err := ic.GetByID(plugins.DiffPlugin, uc.Differ) |
| 170 | if err != nil { |
| 171 | if uc.Optional { |
| 172 | return nil, true, nil |
| 173 | } |
| 174 | return nil, false, fmt.Errorf("failed to get instance for diff plugin %q: %w", uc.Differ, err) |
| 175 | } |
| 176 | return inst.(diff.Applier), false, nil |
| 177 | } |
| 178 | |
| 179 | var ( |
| 180 | applier diff.Applier |
| 181 | applierID string |
| 182 | ) |
| 183 | for _, candidate := range ic.GetAll() { |
| 184 | if candidate.Registration.Type != plugins.DiffPlugin { |
| 185 | continue |
| 186 | } |
| 187 | var matched bool |
| 188 | for _, pd := range candidate.Meta.Platforms { |
| 189 | // Note that we must use the platforms supported by the differ to |
| 190 | // match the platform in `UnpackConfiguration`. |
| 191 | // |
| 192 | // For example, a differ might only support "linux/amd64", while |
| 193 | // the platform in `UnpackConfiguration` is "linux(+erofs)/amd64". |
| 194 | // If we reverse this logic, this wrong differ will be applied. |
| 195 | if platforms.Only(pd).Match(p) { |
| 196 | matched = true |
| 197 | } |
| 198 | } |
| 199 | if !matched { |
| 200 | continue |
| 201 | } |
| 202 | if applier != nil { |
| 203 | skippedApplier := candidate.Registration.ID |
| 204 | |
| 205 | // Prefer the default when multiple plugins match |
| 206 | if skippedApplier == defaults.DefaultDiffer { |
| 207 | skippedApplier = applierID |
| 208 | } |
| 209 | |
| 210 | log.G(ic.Context).Warnf("multiple differs match for platform, set `differ` option to choose, skipping %q", skippedApplier) |
| 211 | |
| 212 | if candidate.Registration.ID == skippedApplier { |
| 213 | continue |
| 214 | } |
| 215 | } |
| 216 | inst, err := candidate.Instance() |
| 217 | if err != nil { |
| 218 | if plugin.IsSkipPlugin(err) { |
| 219 | continue |
| 220 | } |
| 221 | if uc.Optional { |
| 222 | return nil, true, nil |
| 223 | } |
| 224 | return nil, false, fmt.Errorf("failed to get instance for diff plugin %q: %w", candidate.Registration.ID, err) |
no test coverage detected
searching dependent graphs…