mountPairToLayerStack ensures that the two sets of mount-lists are actually a correct parent-and-child, or orphan-and-empty-list, and return the full list of layers, starting with the upper-most (most childish?)
(lower, upper []mount.Mount)
| 356 | // parent-and-child, or orphan-and-empty-list, and return the full list of layers, starting |
| 357 | // with the upper-most (most childish?) |
| 358 | func mountPairToLayerStack(lower, upper []mount.Mount) ([]string, error) { |
| 359 | |
| 360 | // May return an ErrNotImplemented, which will fall back to LCOW |
| 361 | upperLayer, upperParentLayerPaths, err := mountsToLayerAndParents(upper) |
| 362 | if err != nil { |
| 363 | return nil, fmt.Errorf("upper mount invalid: %w", err) |
| 364 | } |
| 365 | |
| 366 | lowerLayer, lowerParentLayerPaths, err := mountsToLayerAndParents(lower) |
| 367 | if errdefs.IsNotImplemented(err) { |
| 368 | // Upper was a windows-layer, lower is not. We can't handle that. |
| 369 | return nil, fmt.Errorf("windowsDiff cannot diff a windows-layer against a non-windows-layer: %w", errdefs.ErrInvalidArgument) |
| 370 | } else if err != nil { |
| 371 | return nil, fmt.Errorf("lower mount invalid: %w", err) |
| 372 | } |
| 373 | |
| 374 | // Trivial case, diff-against-nothing |
| 375 | if lowerLayer == "" { |
| 376 | if len(upperParentLayerPaths) != 0 { |
| 377 | return nil, fmt.Errorf("windowsDiff cannot diff a layer with parents against a null layer: %w", errdefs.ErrInvalidArgument) |
| 378 | } |
| 379 | return []string{upperLayer}, nil |
| 380 | } |
| 381 | |
| 382 | if len(upperParentLayerPaths) < 1 { |
| 383 | return nil, fmt.Errorf("windowsDiff cannot diff a layer with no parents against another layer: %w", errdefs.ErrInvalidArgument) |
| 384 | } |
| 385 | |
| 386 | if upperParentLayerPaths[0] != lowerLayer { |
| 387 | return nil, fmt.Errorf("windowsDiff cannot diff a layer against a layer other than its own parent: %w", errdefs.ErrInvalidArgument) |
| 388 | } |
| 389 | |
| 390 | if len(upperParentLayerPaths) != len(lowerParentLayerPaths)+1 { |
| 391 | return nil, fmt.Errorf("windowsDiff cannot diff a layer against a layer with different parents: %w", errdefs.ErrInvalidArgument) |
| 392 | } |
| 393 | for i, upperParent := range upperParentLayerPaths[1:] { |
| 394 | if upperParent != lowerParentLayerPaths[i] { |
| 395 | return nil, fmt.Errorf("windowsDiff cannot diff a layer against a layer with different parents: %w", errdefs.ErrInvalidArgument) |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | return append([]string{upperLayer}, upperParentLayerPaths...), nil |
| 400 | } |
| 401 | |
| 402 | func uniqueRef() string { |
| 403 | t := time.Now() |
no test coverage detected
searching dependent graphs…