// As loadAndMergeIfNeeded but lets caller decide how to manage file handles
184548
func (k *Store) loadAndMergeReaderIfNeeded(f io.Reader) error {
	var versionOnDisk int64
	// Decode *only* the version field to check whether anyone else has
	// modified the db; gob serializes structs in order so it will always be 1st
	dec := gob.NewDecoder(f)
	err := dec.Decode(&versionOnDisk)
	if err != nil {
		return fmt.Errorf("Problem checking version of key/value data from %v: %v", k.filename, err)
	}
	// Totally uninitialised Version == 0, saved versions are always >=1
	if versionOnDisk != k.version {
		// Reload data & merge
		var dbOnDisk map[string]interface{}
		err = dec.Decode(&dbOnDisk)
		if err != nil {
			return fmt.Errorf("Problem reading updated key/value data from %v: %v", k.filename, err)
		}
		k.reapplyChanges(dbOnDisk)
		k.version = versionOnDisk
	}
	return nil
}
1056769
func LoadFromFile(fname string) (tr *Trie, err error) {
	tr = NewTrie()
	entries, err := loadTrieFile(fname)
	if err != nil {
		return
	}
	log.Printf("Got %v entries\n", len(entries))
	startTime := time.Now()
	for _, mi := range entries {
		b := tr.Add(mi.Value)
		b.Count = mi.Count
	}
	log.Printf("adding words to index took: %v\n", time.Since(startTime))

	return
}
120122
func CompileAndLoad(ctx context.Context, ep endpoint, stats *SpanStat) error {
	if ep == nil {
		log.Fatalf("LoadBPF() doesn't support non-endpoint load")
	}

	dirs := directoryInfo{
		Library: option.Config.BpfDir,
		Runtime: option.Config.StateDir,
		State:   ep.StateDir(),
		Output:  ep.StateDir(),
	}
	return compileAndLoad(ctx, ep, &dirs, stats)
}
825875
func FileHandlerFunc(filePath string) func(http.ResponseWriter, *http.Request) {
	return func(responseWriter http.ResponseWriter, request *http.Request) {
		http.ServeFile(responseWriter, request, filePath)
	}
}
1272047
func (cb *CacheBuilder) LoaderFunc(loaderFunc LoaderFunc) *CacheBuilder {
	cb.loaderExpireFunc = func(k interface{}) (interface{}, *time.Duration, error) {
		v, err := loaderFunc(k)
		return v, nil, err
	}
	return cb
}
1231750
func LoadFixtureFiles(db *sql.DB, helper Helper, files ...string) error {
	c, err := NewFiles(db, helper, files...)
	if err != nil {
		return err
	}

	return c.Load()
}
675335
func (info Info) MergeWithConfig(c restclient.Config) (restclient.Config, error) {
	var config restclient.Config = c
	config.Username = info.User
	config.Password = info.Password
	config.CAFile = info.CAFile
	config.CertFile = info.CertFile
	config.KeyFile = info.KeyFile
	config.BearerToken = info.BearerToken
	if info.Insecure != nil {
		config.Insecure = *info.Insecure
	}
	return config, nil
}
357947
func (g *Gitlab) ProjectMergeRequestChanges(id, merge_request_id string) (*MergeRequestChanges, *ResponseMeta, error) {
	u := g.ResourceUrl(ProjectMergeRequestChangesApiPath, map[string]string{
		":id":               id,
		":merge_request_id": merge_request_id,
	})

	var err error
	changes := new(MergeRequestChanges)

	contents, meta, err := g.buildAndExecRequest("GET", u.String(), nil)
	if err == nil {
		err = json.Unmarshal(contents, &changes)
	}

	return changes, meta, err
}
75516
func Load(fname string) (err error) {
  var buff []byte
  buff, err = ioutil.ReadFile(fname)
  if err == nil {
    err = json.Unmarshal(buff, MailServer)
  }
  return
}
1041426
func mergeAndWriteMetadata(
	stor storage.Storage, toolsDir, stream string, clean bool, toolsList coretools.List, writeMirrors envtools.ShouldWriteMirrors,
) error {
	existing, err := envtools.ReadAllMetadata(stor)
	if err != nil {
		return err
	}
	if clean {
		delete(existing, stream)
	}
	metadata := envtools.MetadataFromTools(toolsList, toolsDir)
	var mergedMetadata []*envtools.ToolsMetadata
	if mergedMetadata, err = envtools.MergeMetadata(metadata, existing[stream]); err != nil {
		return err
	}
	if err = envtools.ResolveMetadata(stor, toolsDir, mergedMetadata); err != nil {
		return err
	}
	existing[stream] = mergedMetadata
	return envtools.WriteMetadata(stor, existing, []string{stream}, writeMirrors)
}
1300041
func (c *ContainerServer) LoadSandbox(id string) error {
	config, err := c.store.FromContainerDirectory(id, "config.json")
	if err != nil {
		return err
	}
	var m rspec.Spec
	if err = json.Unmarshal(config, &m); err != nil {
		return err
	}
	labels := make(map[string]string)
	if err = json.Unmarshal([]byte(m.Annotations[annotations.Labels]), &labels); err != nil {
		return err
	}
	name := m.Annotations[annotations.Name]
	name, err = c.ReservePodName(id, name)
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			c.ReleasePodName(name)
		}
	}()
	var metadata pb.PodSandboxMetadata
	if err = json.Unmarshal([]byte(m.Annotations[annotations.Metadata]), &metadata); err != nil {
		return err
	}

	dupLabels, err := label.DupSecOpt(m.Process.SelinuxLabel)
	if err != nil {
		return err
	}

	processLabel, mountLabel, err := label.InitLabels(dupLabels)
	if err != nil {
		return err
	}

	spp := m.Annotations[annotations.SeccompProfilePath]

	kubeAnnotations := make(map[string]string)
	if err = json.Unmarshal([]byte(m.Annotations[annotations.Annotations]), &kubeAnnotations); err != nil {
		return err
	}

	portMappings := []*hostport.PortMapping{}
	if err := json.Unmarshal([]byte(m.Annotations[annotations.PortMappings]), &portMappings); err != nil {
		return err
	}

	privileged := isTrue(m.Annotations[annotations.PrivilegedRuntime])
	hostNetwork := isTrue(m.Annotations[annotations.HostNetwork])
	nsOpts := pb.NamespaceOption{}
	if err := json.Unmarshal([]byte(m.Annotations[annotations.NamespaceOptions]), &nsOpts); err != nil {
		return err
	}

	sb, err := sandbox.New(id, m.Annotations[annotations.Namespace], name, m.Annotations[annotations.KubeName], filepath.Dir(m.Annotations[annotations.LogPath]), labels, kubeAnnotations, processLabel, mountLabel, &metadata, m.Annotations[annotations.ShmPath], m.Annotations[annotations.CgroupParent], privileged, m.Annotations[annotations.RuntimeHandler], m.Annotations[annotations.ResolvPath], m.Annotations[annotations.HostName], portMappings, hostNetwork)
	if err != nil {
		return err
	}
	sb.AddHostnamePath(m.Annotations[annotations.HostnamePath])
	sb.SetSeccompProfilePath(spp)
	sb.SetNamespaceOptions(&nsOpts)

	// We add a netNS only if we can load a permanent one.
	// Otherwise, the sandbox will live in the host namespace.
	if c.config.ManageNetworkNSLifecycle {
		netNsPath, err := configNetNsPath(&m)
		if err == nil {
			nsErr := sb.NetNsJoin(netNsPath, sb.Name())
			// If we can't load the networking namespace
			// because it's closed, we just set the sb netns
			// pointer to nil. Otherwise we return an error.
			if nsErr != nil && nsErr != sandbox.ErrClosedNetNS {
				return nsErr
			}
		}
	}

	if err := c.AddSandbox(sb); err != nil {
		return err
	}

	defer func() {
		if err != nil {
			if err := c.RemoveSandbox(sb.ID()); err != nil {
				logrus.Warnf("could not remove sandbox ID %s: %v", sb.ID(), err)
			}
		}
	}()

	sandboxPath, err := c.store.ContainerRunDirectory(id)
	if err != nil {
		return err
	}

	sandboxDir, err := c.store.ContainerDirectory(id)
	if err != nil {
		return err
	}

	cname, err := c.ReserveContainerName(m.Annotations[annotations.ContainerID], m.Annotations[annotations.ContainerName])
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			c.ReleaseContainerName(cname)
		}
	}()

	created, err := time.Parse(time.RFC3339Nano, m.Annotations[annotations.Created])
	if err != nil {
		return err
	}

	scontainer, err := oci.NewContainer(m.Annotations[annotations.ContainerID], cname, sandboxPath, m.Annotations[annotations.LogPath], sb.NetNs().Path(), labels, m.Annotations, kubeAnnotations, "", "", "", nil, id, false, false, false, privileged, sb.RuntimeHandler(), sandboxDir, created, m.Annotations["org.opencontainers.image.stopSignal"])
	if err != nil {
		return err
	}
	scontainer.SetSpec(&m)
	scontainer.SetMountPoint(m.Annotations[annotations.MountPoint])

	if m.Annotations[annotations.Volumes] != "" {
		containerVolumes := []oci.ContainerVolume{}
		if err = json.Unmarshal([]byte(m.Annotations[annotations.Volumes]), &containerVolumes); err != nil {
			return fmt.Errorf("failed to unmarshal container volumes: %v", err)
		}
		for _, cv := range containerVolumes {
			scontainer.AddVolume(cv)
		}
	}

	c.ContainerStateFromDisk(scontainer)
	sb.SetCreated()

	if err = label.ReserveLabel(processLabel); err != nil {
		return err
	}
	sb.SetInfraContainer(scontainer)
	if err = c.ctrIDIndex.Add(scontainer.ID()); err != nil {
		return err
	}
	if err = c.podIDIndex.Add(id); err != nil {
		return err
	}
	return nil
}
1241956
func (s *Server) RegisterFileHandler(scheme string, handler FileHandler) {
	if handler == nil {
		delete(s.schemes, scheme)
		return
	}
	s.schemes[scheme] = handler
}
50995
func (p *PullRequest) GetMerged() bool {
	if p == nil || p.Merged == nil {
		return false
	}
	return *p.Merged
}
42348
func JsonMergeStruct(dest, src interface{}) {
	// Not the most efficient approach, but simple & relatively well defined
	j, err := json.Marshal(src)
	if err != nil {
		glog.Fatalf("error marshaling config: %v", err)
	}
	err = json.Unmarshal(j, dest)
	if err != nil {
		glog.Fatalf("error unmarshaling config: %v", err)
	}
}
998910
func LoadGIFRW(src *sdl.RWops) (*sdl.Surface, error) {
	_src := (*C.SDL_RWops)(unsafe.Pointer(src))
	_surface := C.IMG_LoadGIF_RW(_src)
	if _surface == nil {
		return nil, GetError()
	}
	return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
}
1001405
func (r *Registry) loadServices(file *File) error {
	glog.V(1).Infof("Loading services from %s", file.GetName())
	var svcs []*Service
	for _, sd := range file.GetService() {
		glog.V(2).Infof("Registering %s", sd.GetName())
		svc := &Service{
			File: file,
			ServiceDescriptorProto: sd,
		}
		for _, md := range sd.GetMethod() {
			glog.V(2).Infof("Processing %s.%s", sd.GetName(), md.GetName())
			opts, err := extractAPIOptions(md)
			if err != nil {
				glog.Errorf("Failed to extract HttpRule from %s.%s: %v", svc.GetName(), md.GetName(), err)
				return err
			}
			optsList := r.LookupExternalHTTPRules((&Method{Service: svc, MethodDescriptorProto: md}).FQMN())
			if opts != nil {
				optsList = append(optsList, opts)
			}
			if len(optsList) == 0 {
				glog.V(1).Infof("Found non-target method: %s.%s", svc.GetName(), md.GetName())
			}
			meth, err := r.newMethod(svc, md, optsList)
			if err != nil {
				return err
			}
			svc.Methods = append(svc.Methods, meth)
		}
		if len(svc.Methods) == 0 {
			continue
		}
		glog.V(2).Infof("Registered %s with %d method(s)", svc.GetName(), len(svc.Methods))
		svcs = append(svcs, svc)
	}
	file.Services = svcs
	return nil
}
262694
func Merge(fs ...Resource) (Resource, error) {
	if len(fs) < 1 {
		return nil, fmt.Errorf("please provide a resource to merge")
	}

	if len(fs) == 1 {
		return fs[0], nil
	}

	var paths []string
	var digests []digest.Digest
	bypath := map[string][]Resource{}

	// The attributes are all compared against the first to make sure they
	// agree before adding to the above collections. If any of these don't
	// correctly validate, the merge fails.
	prototype := fs[0]
	xattrs := make(map[string][]byte)

	// initialize xattrs for use below. All files must have same xattrs.
	if prototypeXAttrer, ok := prototype.(XAttrer); ok {
		for attr, value := range prototypeXAttrer.XAttrs() {
			xattrs[attr] = value
		}
	}

	for _, f := range fs {
		h, isHardlinkable := f.(Hardlinkable)
		if !isHardlinkable {
			return nil, errNotAHardLink
		}

		if f.Mode() != prototype.Mode() {
			return nil, fmt.Errorf("modes do not match: %v != %v", f.Mode(), prototype.Mode())
		}

		if f.UID() != prototype.UID() {
			return nil, fmt.Errorf("uid does not match: %v != %v", f.UID(), prototype.UID())
		}

		if f.GID() != prototype.GID() {
			return nil, fmt.Errorf("gid does not match: %v != %v", f.GID(), prototype.GID())
		}

		if xattrer, ok := f.(XAttrer); ok {
			fxattrs := xattrer.XAttrs()
			if !reflect.DeepEqual(fxattrs, xattrs) {
				return nil, fmt.Errorf("resource %q xattrs do not match: %v != %v", f, fxattrs, xattrs)
			}
		}

		for _, p := range h.Paths() {
			pfs, ok := bypath[p]
			if !ok {
				// ensure paths are unique by only appending on a new path.
				paths = append(paths, p)
			}

			bypath[p] = append(pfs, f)
		}

		if regFile, isRegFile := f.(RegularFile); isRegFile {
			prototypeRegFile, prototypeIsRegFile := prototype.(RegularFile)
			if !prototypeIsRegFile {
				return nil, errors.New("prototype is not a regular file")
			}

			if regFile.Size() != prototypeRegFile.Size() {
				return nil, fmt.Errorf("size does not match: %v != %v", regFile.Size(), prototypeRegFile.Size())
			}

			digests = append(digests, regFile.Digests()...)
		} else if device, isDevice := f.(Device); isDevice {
			prototypeDevice, prototypeIsDevice := prototype.(Device)
			if !prototypeIsDevice {
				return nil, errors.New("prototype is not a device")
			}

			if device.Major() != prototypeDevice.Major() {
				return nil, fmt.Errorf("major number does not match: %v != %v", device.Major(), prototypeDevice.Major())
			}
			if device.Minor() != prototypeDevice.Minor() {
				return nil, fmt.Errorf("minor number does not match: %v != %v", device.Minor(), prototypeDevice.Minor())
			}
		} else if _, isNamedPipe := f.(NamedPipe); isNamedPipe {
			_, prototypeIsNamedPipe := prototype.(NamedPipe)
			if !prototypeIsNamedPipe {
				return nil, errors.New("prototype is not a named pipe")
			}
		} else {
			return nil, errNotAHardLink
		}
	}

	sort.Stable(sort.StringSlice(paths))

	// Choose a "canonical" file. Really, it is just the first file to sort
	// against. We also effectively select the very first digest as the
	// "canonical" one for this file.
	first := bypath[paths[0]][0]

	resource := resource{
		paths:  paths,
		mode:   first.Mode(),
		uid:    first.UID(),
		gid:    first.GID(),
		xattrs: xattrs,
	}

	switch typedF := first.(type) {
	case RegularFile:
		var err error
		digests, err = uniqifyDigests(digests...)
		if err != nil {
			return nil, err
		}

		return &regularFile{
			resource: resource,
			size:     typedF.Size(),
			digests:  digests,
		}, nil
	case Device:
		return &device{
			resource: resource,
			major:    typedF.Major(),
			minor:    typedF.Minor(),
		}, nil

	case NamedPipe:
		return &namedPipe{
			resource: resource,
		}, nil

	default:
		return nil, errNotAHardLink
	}
}