diff --git a/plugins/snapshots/erofs/erofsutils/mount_linux.go b/plugins/snapshots/erofs/erofsutils/mount_linux.go index b1a0a1a9d..a2e95f04e 100644 --- a/plugins/snapshots/erofs/erofsutils/mount_linux.go +++ b/plugins/snapshots/erofs/erofsutils/mount_linux.go @@ -55,7 +55,8 @@ func ConvertErofs(ctx context.Context, layerPath string, srcDir string, mkfsExtr return nil } -// Get the snapshot layer directory in order to generate EROFS-formatted blobs; +// MountsToLayer returns the snapshot layer directory in order to generate +// EROFS-formatted blobs; // // If mount[0].Type is `bind` or `erofs`, it just tries the source dir; Or if // mount[0].Type is `overlayfs`, it tries the parent of the upperdir; @@ -64,25 +65,29 @@ func ConvertErofs(ctx context.Context, layerPath string, srcDir string, mkfsExtr // snapshot is really generated by the EROFS snapshotter instead of others. func MountsToLayer(mounts []mount.Mount) (string, error) { var layer string - mnt := mounts[0] - if mnt.Type == "bind" || mnt.Type == "erofs" { + switch mnt := mounts[0]; mnt.Type { + case "bind", "erofs": layer = filepath.Dir(mnt.Source) - } else if mnt.Type == "overlay" { - toplower := "" + case "overlay": + var topLower string for _, o := range mnt.Options { - if strings.HasPrefix(o, "upperdir=") { - layer = filepath.Dir(strings.TrimPrefix(o, "upperdir=")) - } else if strings.HasPrefix(o, "lowerdir=") { - toplower = filepath.Dir(strings.Split(strings.TrimPrefix(o, "lowerdir="), ":")[0]) + if k, v, ok := strings.Cut(o, "="); ok { + switch k { + case "upperdir": + layer = filepath.Dir(v) + case "lowerdir": + dir, _, _ := strings.Cut(v, ":") + topLower = filepath.Dir(dir) + } } } if layer == "" { - if toplower == "" { + if topLower == "" { return "", fmt.Errorf("unsupported overlay layer for erofs differ: %w", errdefs.ErrNotImplemented) } - layer = toplower + layer = topLower } - } else { + default: return "", fmt.Errorf("invalid filesystem type for erofs differ: %w", errdefs.ErrNotImplemented) } // If the layer is not prepared by the EROFS snapshotter, fall back to the next differ