// ResolveAutoLongestPath finds the longest local path in each conflict
// and set it to be used.
481412
func ResolveAutoLongestPath(cc []*Conflict) []*Conflict {
	for _, c := range cc {
		if c.Resolved {
			continue
		}
		longestLen := 0
		longestIndex := 0
		for i, op := range c.Operation {
			if op.State != OpReady {
				continue
			}

			if len(op.Pkg.Local) > longestLen {
				longestLen = len(op.Pkg.Local)
				longestIndex = i
			}
		}
		c.OpIndex = longestIndex
		c.Resolved = true
	}
	return cc
}
1023820
func ValidateAbsolutePath(path string, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	if !filepath.IsAbs(path) {
		allErrs = append(allErrs, field.Invalid(fldPath, path, "path is not absolute"))
	}
	return allErrs
}
509332
func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (path.Path, error) {
	if strings.HasPrefix(p.String(), "/ipns/") {
		evt := log.EventBegin(ctx, "resolveIpnsPath")
		defer evt.Done()
		// resolve ipns paths

		// TODO(cryptix): we should be able to query the local cache for the path
		if nsys == nil {
			evt.Append(logging.LoggableMap{"error": ErrNoNamesys.Error()})
			return "", ErrNoNamesys
		}

		seg := p.Segments()

		if len(seg) < 2 || seg[1] == "" { // just "/<protocol/>" without further segments
			evt.Append(logging.LoggableMap{"error": path.ErrNoComponents.Error()})
			return "", path.ErrNoComponents
		}

		extensions := seg[2:]
		resolvable, err := path.FromSegments("/", seg[0], seg[1])
		if err != nil {
			evt.Append(logging.LoggableMap{"error": err.Error()})
			return "", err
		}

		respath, err := nsys.Resolve(ctx, resolvable.String())
		if err != nil {
			evt.Append(logging.LoggableMap{"error": err.Error()})
			return "", err
		}

		segments := append(respath.Segments(), extensions...)
		p, err = path.FromSegments("/", segments...)
		if err != nil {
			evt.Append(logging.LoggableMap{"error": err.Error()})
			return "", err
		}
	}
	return p, nil
}
406517
func (u *URI) ResolveFilePath(p string) string {
	return cleanPath(path.Join(u.FilePath(), strings.TrimPrefix(p, "/")))
}
1125620
func (k *Kubernetes) AutoPath(state request.Request) []string {
	// Check if the query falls in a zone we are actually authoritative for and thus if we want autopath.
	zone := plugin.Zones(k.Zones).Matches(state.Name())
	if zone == "" {
		return nil
	}

	// cluster.local {
	//    autopath @kubernetes
	//    kubernetes {
	//        pods verified #
	//    }
	// }
	// if pods != verified will cause panic and return SERVFAIL, expect worked as normal without autopath function
	if !k.opts.initPodCache {
		return nil
	}

	ip := state.IP()

	pod := k.podWithIP(ip)
	if pod == nil {
		return nil
	}

	search := make([]string, 3)
	if zone == "." {
		search[0] = pod.Namespace + ".svc."
		search[1] = "svc."
		search[2] = "."
	} else {
		search[0] = pod.Namespace + ".svc." + zone
		search[1] = "svc." + zone
		search[2] = zone
	}

	search = append(search, k.autoPathSearch...)
	search = append(search, "") // sentinel
	return search
}
768980
func (r *ProquintResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
	return resolve(ctx, r, name, opts.ProcessOpts(options))
}
19877
func (provider *DashboardProvisionerImpl) GetProvisionerResolvedPath(name string) string {
	for _, reader := range provider.fileReaders {
		if reader.Cfg.Name == name {
			return reader.resolvedPath()
		}
	}
	return ""
}
910782
func validatePath(fs []string, requestBase string) bool {

	for _, a := range fs {
		str1 := strings.Replace(a, "**", "(.*)", -1)
		str2 := strings.Replace(a, "*", "([^/]+)", -1)
		if a != str1 {
			reg, _ := regexp.Compile(str1)
			res := reg.MatchString(requestBase)
			if res == true {
				return true
			}
		} else if a != str2 {
			reg, _ := regexp.Compile(str2)
			res := reg.MatchString(requestBase)
			if res == true {
				return true
			}
		} else if requestBase == a {
			return true
		}

		/*
		 * FIXME: SINGLE_FORWARD_SLASH_PATTERN not supported yet
		 */
	}
	/* if the i/p resource is empty, no checks need to be made */
	return len(fs) == 0
}
1239689
func addResolvedPath(db application.DB, req *http.Request, mArea *area.Area, sArea *app.Area) error {
	pathResolved, error := getResolvePath(db, mArea)
	sArea.Attributes.ParentPathResolved = pathResolved
	return error
}
131037
func RelAppRootfsPath(appName types.ACName) string {
	return filepath.Join(RelAppPath(appName), aci.RootfsDir)
}
16936
func (f *Facade) ResolveServicePath(ctx datastore.Context, svcPath string, noprefix bool) ([]service.ServiceDetails, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.ResolveServicePath"))
	var (
		parent  string
		current string
		result  = []service.ServiceDetails{}
	)
	plog := plog.WithFields(log.Fields{
		"svcpath": svcPath,
	})

	// Empty paths match nothing
	if isEmptyPath(svcPath) {
		plog.Debug("Empty path produced empty result")
		return result, nil
	}

	// Clean up trailing slashes and lowercase the requested path
	svcPath = strings.TrimRight(svcPath, "/")
	svcPath = strings.ToLower(svcPath)

	// First pass: get all services that match either ID exactly or name by regex.
	// The default matching is to use a "contains" regex. This is overridable
	// via the noprefix boolean which changes the regex to an "ends with" match
	parent, current = path.Split(svcPath)

	details, err := f.serviceStore.GetServiceDetailsByIDOrName(ctx, current, noprefix)
	if err != nil {
		return nil, err
	}
	plog.WithFields(log.Fields{
		"svcPath": svcPath,
		"current": current,
		"noprefix":  noprefix,
		"matches": len(details),
	}).Debug("Found possible service matches")

	// Populate the ancestry for all of the found services, so we can check
	// their parents
	for _, detail := range details {
		d, err := f.GetServiceDetailsAncestry(ctx, detail.ID)
		if err != nil {
			return nil, err
		}
		result = append(result, *d)
	}

	// Now walk up the path, filtering parents as we go
	level := 1
	for !isEmptyPath(parent) {
		// Split the path to get the segment at this level
		parent, current = path.Split(strings.TrimRight(parent, "/"))

		// Technically this won't ever be needed, as it gets lowered in cli/cmd
		// before it gets here, but for the sake of local clarity...
		current = strings.ToLower(current)

		filtered := make([]service.ServiceDetails, 0)

		// Walk up parents to the current level and check their names to filter
		// the list of potentials
		for _, d := range result {
			p := &d
			for i := 0; i < level; i++ {
				p = p.Parent
				if p == nil {
					break
				}
			}

			// If the parent name at this level matches OR this is the last
			// segment and it matches the deployment ID, it's considered
			// a match
			if (p != nil && strings.ToLower(p.Name) == current) || (isEmptyPath(parent) && strings.ToLower(d.DeploymentID) == current) {
				filtered = append(filtered, d)
			}
		}
		result = filtered
		level++
	}
	plog.WithField("results", len(result)).Debug("Filtered service matches by parent")

	return result, nil
}
993174
func (s *Sprocket) resolvePath(assetPath string, baseDir string, forceRebuild bool) (string, *types.ExtensionInfo, error) {
	var err error
	ext := filepath.Ext(assetPath)
	extInfo := s.getExtensionInfoOrDefault(ext)
	if forceRebuild == false {
		assetPublicPath, _ := s.checkPublicPath(assetPath, baseDir)
		if len(assetPublicPath) > 0 {
			return assetPublicPath, extInfo, nil
		}
	}
	assetPath, ext, err = resolvePath(extInfo, assetPath, baseDir)
	if err != nil {
		return "", nil, err
	}
	return assetPath, s.getExtensionInfoOrDefault(ext), nil
}
1150918
func (c *Client) ResolveServicePath(path string, noprefix bool) ([]service.ServiceDetails, error) {
	resolveServiceRequest := ResolveServiceRequest{
		Path: path,
		NoPrefix: noprefix,
	}
	svcs := []service.ServiceDetails{}

	plog.WithFields(logrus.Fields{
                "path": path,
                "noprefix": noprefix,
        }).Info("Trying to find service")

	err := c.call("ResolveServicePath", resolveServiceRequest, &svcs)
        return svcs, err
}
724190
func (api *CoreAPI) ResolvePath(ctx context.Context, p path.Path) (path.Resolved, error) {
	if _, ok := p.(path.Resolved); ok {
		return p.(path.Resolved), nil
	}
	if err := p.IsValid(); err != nil {
		return nil, err
	}

	ipath := ipfspath.Path(p.String())
	ipath, err := resolve.ResolveIPNS(ctx, api.namesys, ipath)
	if err == resolve.ErrNoNamesys {
		return nil, coreiface.ErrOffline
	} else if err != nil {
		return nil, err
	}

	var resolveOnce resolver.ResolveOnce

	switch ipath.Segments()[0] {
	case "ipfs":
		resolveOnce = uio.ResolveUnixfsOnce
	case "ipld":
		resolveOnce = resolver.ResolveSingle
	default:
		return nil, fmt.Errorf("unsupported path namespace: %s", p.Namespace())
	}

	r := &resolver.Resolver{
		DAG:         api.dag,
		ResolveOnce: resolveOnce,
	}

	node, rest, err := r.ResolveToLastNode(ctx, ipath)
	if err != nil {
		return nil, err
	}

	root, err := cid.Parse(ipath.Segments()[1])
	if err != nil {
		return nil, err
	}

	return path.NewResolvedPath(ipath, node, root, gopath.Join(rest...)), nil
}
603669
func ResolveRootfs(uncleanRootfs string) (string, error) {
	rootfs, err := filepath.Abs(uncleanRootfs)
	if err != nil {
		return "", err
	}
	return filepath.EvalSymlinks(rootfs)
}
776124
func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (coreiface.Path, error) {
	results, err := api.Search(ctx, name, opts...)
	if err != nil {
		return nil, err
	}

	err = coreiface.ErrResolveFailed
	var p coreiface.Path

	for res := range results {
		p, err = res.Path, res.Err
		if err != nil {
			break
		}
	}

	return p, err
}
220684
func Resolve(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver, p path.Path) (ipld.Node, error) {
	p, err := ResolveIPNS(ctx, nsys, p)
	if err != nil {
		return nil, err
	}

	// ok, we have an IPFS path now (or what we'll treat as one)
	return r.ResolvePath(ctx, p)
}