// getAncestry computes an image ancestry, returning an ordered list
// of dependencies starting from the topmost image to the base.
// It checks for dependency loops via duplicate detection in the image
// chain and errors out in such cases.
354279
func getAncestry(file *os.File, imgID string, debug log.Logger) ([]string, error) {
	var ancestry []string
	deps := make(map[string]bool)

	curImgID := imgID

	var err error
	for curImgID != "" {
		if deps[curImgID] {
			return nil, fmt.Errorf("dependency loop detected at image %q", curImgID)
		}
		deps[curImgID] = true
		ancestry = append(ancestry, curImgID)
		debug.Printf("Getting ancestry for layer %q", curImgID)
		curImgID, err = getParent(file, curImgID, debug)
		if err != nil {
			return nil, err
		}
	}
	return ancestry, nil
}
722959
func getFirstParent(cert *x509.Certificate, certs []*x509.Certificate) *x509.Certificate {
	for _, c := range certs {
		if cert.Issuer.CommonName == c.Subject.CommonName { //TODO : consider changing this check with validating check
			return c
		}
	}
	//parent not found
	return nil
}
1364642
func (p *PushEventRepository) GetHomepage() string {
	if p == nil || p.Homepage == nil {
		return ""
	}
	return *p.Homepage
}
1059391
func (r *Session) GetRemoteHistory(imgID, registry string) ([]string, error) {
	res, err := r.client.Get(registry + "images/" + imgID + "/ancestry")
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	if res.StatusCode != 200 {
		if res.StatusCode == 401 {
			return nil, errcode.ErrorCodeUnauthorized.WithArgs()
		}
		return nil, newJSONError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
	}

	var history []string
	if err := json.NewDecoder(res.Body).Decode(&history); err != nil {
		return nil, fmt.Errorf("Error while reading the http response: %v", err)
	}

	logrus.Debugf("Ancestry: %v", history)
	return history, nil
}
1309452
func VirtualRootsGet(xu *xgbutil.XUtil) ([]xproto.Window, error) {
	return xprop.PropValWindows(xprop.GetProperty(xu, xu.RootWin(),
		"_NET_VIRTUAL_ROOTS"))
}
903749
func findAncestorStepId(step *flow.Step) (int, bool) {
	current := step
	taskCount := len(current.Tasks)

	// println("find step", step.Name)

	for taskCount == len(current.Tasks) {
		if len(current.InputDatasets) > 1 {
			// more than 2 dataset inputs
			break
		}
		if len(current.InputDatasets) == 0 {
			// no dataset inputs
			break
		}
		if !isMergeableDataset(current.InputDatasets[0], taskCount) {
			break
		}
		if (!current.IsOnDriverSide && current.InputDatasets[0].Step.IsOnDriverSide) ||
			(current.IsOnDriverSide && !current.InputDatasets[0].Step.IsOnDriverSide) {
			break
		}

		current = current.InputDatasets[0].Step
		taskCount = len(current.Tasks)

	}
	return current.Id, true
}
1272596
func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
	if refOrID == "" { // ie FROM scratch
		os := runtime.GOOS
		if opts.Platform != nil {
			os = opts.Platform.OS
		}
		if !system.IsOSSupported(os) {
			return nil, nil, system.ErrNotSupportedOperatingSystem
		}
		layer, err := newROLayerForImage(nil, i.layerStores[os])
		return nil, layer, err
	}

	if opts.PullOption != backend.PullOptionForcePull {
		image, err := i.GetImage(refOrID)
		if err != nil && opts.PullOption == backend.PullOptionNoPull {
			return nil, nil, err
		}
		// TODO: shouldn't we error out if error is different from "not found" ?
		if image != nil {
			if !system.IsOSSupported(image.OperatingSystem()) {
				return nil, nil, system.ErrNotSupportedOperatingSystem
			}
			layer, err := newROLayerForImage(image, i.layerStores[image.OperatingSystem()])
			return image, layer, err
		}
	}

	image, err := i.pullForBuilder(ctx, refOrID, opts.AuthConfig, opts.Output, opts.Platform)
	if err != nil {
		return nil, nil, err
	}
	if !system.IsOSSupported(image.OperatingSystem()) {
		return nil, nil, system.ErrNotSupportedOperatingSystem
	}
	layer, err := newROLayerForImage(image, i.layerStores[image.OperatingSystem()])
	return image, layer, err
}
325826
func (c *Client) GetNonRootMapping(
	ctx context.Context, name string) (UserMapping, error) {

	ex, err := c.GetExportByName(ctx, name)
	if err != nil {
		return nil, err
	}
	if ex == nil {
		return nil, nil
	}
	return ex.MapNonRoot, nil
}
835849
func (mtt *mttNode) GetVersions(ns []string) ([]*metricType, error) {
	var nodes []*mttNode
	var mts []*metricType

	if len(ns) == 0 {
		return nil, errorEmptyNamespace()
	}

	nodes = mtt.search(nodes, ns)

	for _, node := range nodes {
		// concatenates metric types in ALL versions into a single slice
		for _, mt := range node.mts {
			mts = append(mts, mt)
		}
	}
	if len(mts) == 0 {
		return nil, errorMetricNotFound("/" + strings.Join(ns, "/"))
	}
	return mts, nil
}
735812
func (i *ResourceInstance) GetGeneration(gen Generation) *ResourceInstanceObjectSrc {
	if gen == CurrentGen {
		return i.Current
	}
	if dk, ok := gen.(DeposedKey); ok {
		return i.Deposed[dk]
	}
	if gen == nil {
		panic(fmt.Sprintf("get with nil Generation"))
	}
	// Should never fall out here, since the above covers all possible
	// Generation values.
	panic(fmt.Sprintf("get invalid Generation %#v", gen))
}
52601
func (ss *scaleSet) GetInstanceTypeByNodeName(name string) (string, error) {
	managedByAS, err := ss.isNodeManagedByAvailabilitySet(name)
	if err != nil {
		klog.Errorf("Failed to check isNodeManagedByAvailabilitySet: %v", err)
		return "", err
	}
	if managedByAS {
		// vm is managed by availability set.
		return ss.availabilitySet.GetInstanceTypeByNodeName(name)
	}

	_, _, vm, err := ss.getVmssVM(name)
	if err != nil {
		return "", err
	}

	if vm.Sku != nil && vm.Sku.Name != nil {
		return *vm.Sku.Name, nil
	}

	return "", nil
}
276895
func (d *Provider) Get(name string) (interface{}, error) {
	d.Block()
	if d.isCalled(name) {
		return nil, fmt.Errorf("%s is cyclic dependency (dependency callstack: %v)", name, append(d.callstack, name))
	}
	if instance, exist := d.instances[name]; exist {
		return instance, nil
	}
	if factory, exist := d.factories[name]; exist {
		d.callstack = append(d.callstack, name)
		instance, err := factory(d)
		if err != nil {
			return nil, fmt.Errorf("%v (dependency callstack: %v)", err, d.callstack)
		}
		if instance == nil {
			return nil, fmt.Errorf("factory for %s return nil as instance", name)
		}
		d.callstack = d.callstack[:len(d.callstack)-1]
		d.clean(name)
		d.instances[name] = instance
		return instance, nil
	}
	if factory, exist := d.defaultFactories[name]; exist {
		d.callstack = append(d.callstack, name)
		instance, err := factory(d)
		if err != nil {
			return nil, fmt.Errorf("%v (dependency callstack: %v)", err, d.callstack)
		}
		if instance == nil {
			return nil, fmt.Errorf("default factory for %s return nil as instance", name)
		}
		d.callstack = d.callstack[:len(d.callstack)-1]
		if d.autoclean {
			delete(d.defaultFactories, name)
		}
		d.instances[name] = instance
		return instance, nil
	}
	return nil, fmt.Errorf("goatcore/dependency/provider: dependency %s doesn't exist", name)
}
493931
func (az *Cloud) GetVirtualMachineWithRetry(name types.NodeName) (compute.VirtualMachine, error) {
	var machine compute.VirtualMachine
	var retryErr error
	err := wait.ExponentialBackoff(az.requestBackoff(), func() (bool, error) {
		machine, retryErr = az.getVirtualMachine(name)
		if retryErr == cloudprovider.InstanceNotFound {
			return true, cloudprovider.InstanceNotFound
		}
		if retryErr != nil {
			klog.Errorf("GetVirtualMachineWithRetry(%s): backoff failure, will retry, err=%v", name, retryErr)
			return false, nil
		}
		klog.V(2).Infof("GetVirtualMachineWithRetry(%s): backoff success", name)
		return true, nil
	})
	if err == wait.ErrWaitTimeout {
		err = retryErr
	}
	return machine, err
}
567247
func (d *stiDocker) GetImageEntrypoint(name string) ([]string, error) {
	image, err := d.InspectImage(name)
	if err != nil {
		return nil, err
	}
	return image.Config.Entrypoint, nil
}
507727
func (b *Box) GetInnerRect() (int, int, int, int) {
	if b.innerX >= 0 {
		return b.innerX, b.innerY, b.innerWidth, b.innerHeight
	}
	x, y, width, height := b.GetRect()
	if b.border {
		x++
		y++
		width -= 2
		height -= 2
	}
	return x + b.paddingLeft,
		y + b.paddingTop,
		width - b.paddingLeft - b.paddingRight,
		height - b.paddingTop - b.paddingBottom
}
143636
func (l AncestorList) GetDistinctAncestorIDs() id.Slice {
	m := id.Map{}
	for _, ancestor := range l {
		m[ancestor.ID] = struct{}{}
	}
	return m.ToSlice()
}
504573
func (ds *Datastore) GetType(ctx context.Context) (string, error) {
	var dsMo mo.Datastore
	pc := property.DefaultCollector(ds.Client())
	err := pc.RetrieveOne(ctx, ds.Datastore.Reference(), []string{"summary"}, &dsMo)
	if err != nil {
		klog.Errorf("Failed to retrieve datastore summary property. err: %v", err)
		return "", err
	}
	return dsMo.Summary.Type, nil
}