func findSnapshotByRootObjectIDOrManifestID(ctx context.Context, rep repo.Repository, rootID string, consistentAttributes bool) (*snapshot.Manifest, error) {
	m, err := snapshot.LoadSnapshot(ctx, rep, manifest.ID(rootID))
	if err == nil {
		return m, nil
	}

	rootOID, err := object.ParseID(rootID)
	if err != nil {
		return nil, errors.Wrap(err, "error parsing root object ID")
	}

	mans, err := snapshot.FindSnapshotsByRootObjectID(ctx, rep, rootOID)
	if err != nil {
		return nil, errors.Wrapf(err, "unable to find shapshots by ID %v", rootID)
	}

	// no matching snapshots.
	if len(mans) == 0 {
		return nil, nil
	}

	// all snapshots have consistent metadata, pick any.
	if areSnapshotsConsistent(mans) {
		return mans[0], nil
	}

	// at this point we found multiple snapshots with the same root ID which don't agree on other
	// metadata (the attributes, ACLs, ownership, etc. of the root)
	if consistentAttributes {
		return nil, errors.Errorf("found multiple snapshots matching %v with inconsistent root attributes", rootID)
	}

	repoFSLog(ctx).Debugf("Found multiple snapshots matching %v with inconsistent root attributes. Picking latest one.", rootID)

	return latestManifest(mans), nil
}
// findSnapshotByRootObjectIDOrManifestID returns the list of matching snapshots for a given rootID.
// which can be either snapshot manifst ID (which matches 0 or 1 snapshots)
// or the root object ID (which can match arbitrary number of snapshots).
// If multiple snapshots match and they don't agree on root object attributes and consistentAttributes==true
// the function fails, otherwise it returns the latest of the snapshots.
findSnapshotByRootObjectIDOrManifestID returns the list of matching snapshots for a given rootID.
which can be either snapshot manifst ID (which matches 0 or 1 snapshots)
or the root object ID (which can match arbitrary number of snapshots).
If multiple snapshots match and they don't agree on root object attributes and consistentAttributes==true
the function fails, otherwise it returns the latest of the snapshots.
// findSnapshotByRootObjectIDOrManifestID returns the list of matching snapshots for a given rootID . // which can be either snapshot manifst ID ( which matches 0 or 1 snapshots ) // or the root object ID ( which can match arbitrary number of snapshots ) . // If multiple snapshots match and they don ' t agree on root object attributes and consistentAttributes == true // the function fails otherwise it returns the latest of the snapshots .
func findSnapshotByRootObjectIDOrManifestID(ctx context.Context, rep repo.Repository, rootID string, consistentAttributes bool) (*snapshot.Manifest, error) {
	m, err := snapshot.LoadSnapshot(ctx, rep, manifest.ID(rootID))
	if err == nil {
		return m, nil
	}
	rootOID, err := object.ParseID(rootID)
	if err != nil {
		return nil, errors.Wrap(err, "error parsing root object ID")
	}
	mans, err := snapshot.FindSnapshotsByRootObjectID(ctx, rep, rootOID)
	if err != nil {
		return nil, errors.Wrapf(err, "unable to find shapshots by ID %v", rootID)
	}
	if len(mans) == 0 {
		return nil, nil
	}
	if areSnapshotsConsistent(mans) {
		return mans[0], nil
	}
	if consistentAttributes {
		return nil, errors.Errorf("found multiple snapshots matching %v with inconsistent root attributes", rootID)
	}
	repoFSLog(ctx).Debugf("Found multiple snapshots matching %v with inconsistent root attributes. Picking latest one.", rootID)
	return latestManifest(mans), nil
}
func findSnapshotByRootObjectIDOrManifestID ( ctx context . Context , rep repo . Repository , rootID string , consistentAttributes bool ) ( * snapshot . Manifest , error ) { m , err := snapshot . LoadSnapshot ( ctx , rep , manifest . ID ( rootID ) ) if err == nil { return m , nil } rootOID , err := object . ParseID ( rootID ) if err != nil { return nil , errors . Wrap ( err , " " ) } mans , err := snapshot . FindSnapshotsByRootObjectID ( ctx , rep , rootOID ) if err != nil { return nil , errors . Wrapf ( err , " " , rootID ) } if len ( mans ) == 0 { return nil , nil } if areSnapshotsConsistent ( mans ) { return mans [ 0 ] , nil } if consistentAttributes { return nil , errors . Errorf ( " " , rootID ) } repoFSLog ( ctx ) . Debugf ( " " , rootID ) return latestManifest ( mans ) , nil }
findSnapshotByRootObjectIDOrManifestID returns the list of matching snapshots for a given rootID.
findSnapshotByRootObjectIDOrManifestID returns the list of matching snapshots for a given rootID .
// no matching snapshots. // all snapshots have consistent metadata, pick any. // at this point we found multiple snapshots with the same root ID which don't agree on other // metadata (the attributes, ACLs, ownership, etc. of the root)