// Import imports and parses the package with the given path.
// It returns nil if it fails.
545196
func (ctxt *Context) Import(path, srcDir string) *ast.Package {
	// TODO return error.
	return ctxt.importer(path, srcDir)
}
1271734
func (s *NFSBackup) Import(lfile io.Reader) (err error) {
	lo.G.Debug("uploading file for backup")
	if err = s.RemoteOps.UploadFile(lfile); err == nil {
		lo.G.Debug("starting backup from %s", s.RemoteOps.Path())
		err = s.Caller.Execute(ioutil.Discard, s.getRestoreCommand())
	}
	if err == nil {
		lo.G.Debug("backup from %s completed", s.RemoteOps.Path())
	} else {
		lo.G.Debug("backup from %s completed with error %s", s.RemoteOps.Path(), err)
	}
	s.RemoteOps.RemoveRemoteFile()
	return
}
674675
func (p *Secring) Import(buf []byte) error {
	pk := &xcpb.PrivateKey{}
	if err := proto.Unmarshal(buf, pk); err != nil {
		return err
	}

	p.insert(pk)
	return nil
}
1191092
func (bi *blockImporter) Import() chan *importResults {
	// Start up the read and process handling goroutines.  This setup allows
	// blocks to be read from disk in parallel while being processed.
	bi.wg.Add(2)
	go bi.readHandler()
	go bi.processHandler()

	// Wait for the import to finish in a separate goroutine and signal
	// the status handler when done.
	go func() {
		bi.wg.Wait()
		bi.doneChan <- true
	}()

	// Start the status handler and return the result channel that it will
	// send the results on when the import is done.
	resultChan := make(chan *importResults)
	go bi.statusHandler(resultChan)
	return resultChan
}
452820
func (d *Diskv) Import(srcFilename, dstKey string, move bool) (err error) {
	if dstKey == "" {
		return errEmptyKey
	}

	if fi, err := os.Stat(srcFilename); err != nil {
		return err
	} else if fi.IsDir() {
		return errImportDirectory
	}

	dstPathKey := d.transform(dstKey)

	d.mu.Lock()
	defer d.mu.Unlock()

	if err := d.ensurePathWithLock(dstPathKey); err != nil {
		return fmt.Errorf("ensure path: %s", err)
	}

	if move {
		if err := syscall.Rename(srcFilename, d.completeFilename(dstPathKey)); err == nil {
			d.bustCacheWithLock(dstPathKey.originalKey)
			return nil
		} else if err != syscall.EXDEV {
			// If it failed due to being on a different device, fall back to copying
			return err
		}
	}

	f, err := os.Open(srcFilename)
	if err != nil {
		return err
	}
	defer f.Close()
	err = d.writeStreamWithLock(dstPathKey, f, false)
	if err == nil && move {
		err = os.Remove(srcFilename)
	}
	return err
}
1049114
func (p *Parser) Parse(srcPath string, files []models.Path) (*Result, error) {
	b, err := p.readFile(srcPath)
	if err != nil {
		return nil, err
	}
	fset := token.NewFileSet()
	f, err := p.parseFile(fset, srcPath)
	if err != nil {
		return nil, err
	}
	fs, err := p.parseFiles(fset, f, files)
	if err != nil {
		return nil, err
	}
	return &Result{
		Header: &models.Header{
			Comments: parsePkgComment(f, f.Package),
			Package:  f.Name.String(),
			Imports:  parseImports(f.Imports),
			Code:     goCode(b, f),
		},
		Funcs: p.parseFunctions(fset, f, fs),
	}, nil
}
7184
func GoPackagePath(pkg string) (path string, err error) {
	gp := os.Getenv("GOPATH")
	if gp == "" {
		cmd := exec.Command("go", "env", "GOPATH")
		out, err := cmd.Output()
		if err != nil {
			return "", fmt.Errorf("could not run 'go env GOPATH': %v, %s", err, out)
		}
		gp = strings.TrimSpace(string(out))
		if gp == "" {
			return "", os.ErrNotExist
		}
	}
	for _, p := range filepath.SplitList(gp) {
		dir := filepath.Join(p, "src", filepath.FromSlash(pkg))
		fi, err := os.Stat(dir)
		if os.IsNotExist(err) {
			continue
		}
		if err != nil {
			return "", err
		}
		if !fi.IsDir() {
			continue
		}
		return dir, nil
	}
	return path, os.ErrNotExist
}
932178
func (importer *MemoryImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) {
	if content, ok := importer.Data[importedPath]; ok {
		return content, importedPath, nil
	}
	return Contents{}, "", fmt.Errorf("import not available %v", importedPath)
}
596582
func (p *Imports) Get(prev, path string) ([]byte, error) {
	p.RLock()
	defer p.RUnlock()
	for _, imp := range p.m {
		if imp.Prev == prev && imp.Path == path {
			return imp.bytes, nil
		}
	}
	return nil, ErrImportNotFound
}
419762
func (c *Client) Import(
	kind storage.StorageKind,
	storagePool string,
	storageProviderId string,
	storageName string,
) (names.StorageTag, error) {
	var results params.ImportStorageResults
	args := params.BulkImportStorageParams{
		[]params.ImportStorageParams{{
			StorageName: storageName,
			Kind:        params.StorageKind(kind),
			Pool:        storagePool,
			ProviderId:  storageProviderId,
		}},
	}
	if err := c.facade.FacadeCall("Import", args, &results); err != nil {
		return names.StorageTag{}, errors.Trace(err)
	}
	if len(results.Results) != 1 {
		return names.StorageTag{}, errors.Errorf(
			"expected 1 result, got %d",
			len(results.Results),
		)
	}
	if err := results.Results[0].Error; err != nil {
		return names.StorageTag{}, err
	}
	return names.ParseStorageTag(results.Results[0].Result.StorageTag)
}
1170823
func importType(path, name string) types.Type {
	pkg, err := stdImporter.Import(path)
	if err != nil {
		// This can happen if the package at path hasn't been compiled yet.
		warnf("import failed: %v", err)
		return nil
	}
	if obj, ok := pkg.Scope().Lookup(name).(*types.TypeName); ok {
		return obj.Type()
	}
	warnf("invalid type name %q", name)
	return nil
}
608706
func (u Universe) Package(packagePath string) *Package {
	if p, ok := u[packagePath]; ok {
		return p
	}
	p := &Package{
		Path:      packagePath,
		Types:     map[string]*Type{},
		Functions: map[string]*Type{},
		Variables: map[string]*Type{},
		Imports:   map[string]*Package{},
	}
	u[packagePath] = p
	return p
}
115311
func (cmd *ImportCommand) importPath(ctx context.Context, fieldType string, useColumnKeys, useRowKeys bool, path string) error {
	// If fieldType is `int`, treat the import data as values to be range-encoded.
	if fieldType == pilosa.FieldTypeInt {
		return cmd.bufferValues(ctx, useColumnKeys, path)
	}
	return cmd.bufferBits(ctx, useColumnKeys, useRowKeys, path)
}
857521
func (s *Server) Imports() []string {
	imports := map[string]struct{}{}

	for _, r := range s.Resources {
		imports[r.apiName()] = struct{}{}
	}
	return commons.MapToSortedStrings(imports)
}
1076070
func (a *StorageAPI) Import(args params.BulkImportStorageParams) (params.ImportStorageResults, error) {
	if err := a.checkCanWrite(); err != nil {
		return params.ImportStorageResults{}, errors.Trace(err)
	}

	blockChecker := common.NewBlockChecker(a.backend)
	if err := blockChecker.ChangeAllowed(); err != nil {
		return params.ImportStorageResults{}, errors.Trace(err)
	}

	results := make([]params.ImportStorageResult, len(args.Storage))
	for i, arg := range args.Storage {
		details, err := a.importStorage(arg)
		if err != nil {
			results[i].Error = common.ServerError(err)
			continue
		}
		results[i].Result = details
	}
	return params.ImportStorageResults{Results: results}, nil
}
1354823
func (b *Builder) importPackage(dir string, userRequested bool) (*tc.Package, error) {
	klog.V(5).Infof("importPackage %s", dir)
	var pkgPath = importPathString(dir)

	// Get the canonical path if we can.
	if buildPkg := b.buildPackages[dir]; buildPkg != nil {
		canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
		klog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage)
		pkgPath = canonicalPackage
	}

	// If we have not seen this before, process it now.
	ignoreError := false
	if _, found := b.parsed[pkgPath]; !found {
		// Ignore errors in paths that we're importing solely because
		// they're referenced by other packages.
		ignoreError = true

		// Add it.
		if err := b.addDir(dir, userRequested); err != nil {
			return nil, err
		}

		// Get the canonical path now that it has been added.
		if buildPkg := b.buildPackages[dir]; buildPkg != nil {
			canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath)
			klog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage)
			pkgPath = canonicalPackage
		}
	}

	// If it was previously known, just check that the user-requestedness hasn't
	// changed.
	b.userRequested[pkgPath] = userRequested || b.userRequested[pkgPath]

	// Run the type checker.  We may end up doing this to pkgs that are already
	// done, or are in the queue to be done later, but it will short-circuit,
	// and we can't miss pkgs that are only depended on.
	pkg, err := b.typeCheckPackage(pkgPath)
	if err != nil {
		switch {
		case ignoreError && pkg != nil:
			klog.V(2).Infof("type checking encountered some issues in %q, but ignoring.\n", pkgPath)
		case !ignoreError && pkg != nil:
			klog.V(2).Infof("type checking encountered some errors in %q\n", pkgPath)
			return nil, err
		default:
			return nil, err
		}
	}

	return pkg, nil
}
1123683
func (r *resource) Imports() []string {
	ip := map[string]struct{}{}

	for _, m := range r.Methods {
		var names []string
		if m.ReqBody != "" {
			names = append(names, m.ReqBody)
		}
		if m.RespBody != "" {
			names = append(names, m.RespBody)
		}
		for _, name := range names {
			if tipe, ok := objectRegistered(name); ok {
				ip[tipe] = struct{}{}
			}
		}
	}
	return commons.MapToSortedStrings(ip)
}