// importAssembled imports the assembled file shared at si.shareURL.
543685
func (si *shareImporter) importAssembled(ctx context.Context) {
	res, err := http.Get(si.shareURL)
	if err != nil {
		return
	}
	defer res.Body.Close()
	br, err := schema.WriteFileFromReader(ctx, si.dest, "", res.Body)
	if err != nil {
		return
	}
	si.mu.Lock()
	si.br = br
	si.mu.Unlock()
	return
}
1145703
func ImportConfiguration(root string, profile string, overwrite bool) error {
	dirs := listDirectories()
	absRoot, err := determineAbsRoot(root)
	if err != nil {
		return err
	}

	// For every application directory...
	for _, serviceName := range dirs {
		LoggingClient.Debug(fmt.Sprintf("importing: %s/%s", absRoot, serviceName))
		if err != nil {
			return err
		}
		// Find the resource (res) directory...
		res := fmt.Sprintf("%s/%s/res", absRoot, serviceName)

		// Append profile to the path if specified...
		if len(profile) > 0 {
			res += "/" + profile
		}

		//Append configuration file name
		path := res + "/" + internal.ConfigFileName

		if !isTomlExtension(path) {
			return errors.New("unsupported file extension: " + path)
		}

		LoggingClient.Debug("reading toml " + path)

		// load the ToML file
		configuration, err := toml.LoadFile(path)
		if err != nil {
			LoggingClient.Warn(err.Error())
			return nil
		}

		registryConfig := types.Config{
			Host:       Configuration.Registry.Host,
			Port:       Configuration.Registry.Port,
			Type:       Configuration.Registry.Type,
			Stem:       internal.ConfigRegistryStem,
			ServiceKey: internal.ServiceKeyPrefix + serviceName,
		}
		Registry, err = registry.NewRegistryClient(registryConfig)
		if err != nil {
			return err
		}

		Registry.PutConfigurationToml(configuration, overwrite)
	}

	return nil
}
980732
func (ctx *Context) loadPackage() error {
	ctx.loaded = true
	ctx.dirty = false
	ctx.statusCache = nil
	ctx.Package = make(map[string]*Package, len(ctx.Package))
	// We following the root symlink only in case the root of the repo is symlinked into the GOPATH
	// This could happen during on some CI that didn't checkout into the GOPATH
	rootdir, err := filepath.EvalSymlinks(ctx.RootDir)
	if err != nil {
		return err
	}
	err = filepath.Walk(rootdir, func(path string, info os.FileInfo, err error) error {
		if info == nil {
			return err
		}
		if !info.IsDir() {
			// We replace the directory path (followed by the symlink), to the real go repo package name/path
			// ex : replace "<somewhere>/govendor.source.repo" to "github.com/kardianos/govendor"
			path = strings.Replace(path, rootdir, ctx.RootDir, 1)
			_, err = ctx.addFileImports(path, ctx.RootGopath)
			return err
		}
		name := info.Name()
		// Still go into "_workspace" to aid godep migration.
		if name == "_workspace" {
			return nil
		}
		switch name[0] {
		case '.', '_':
			return filepath.SkipDir
		}
		switch name {
		case "testdata", "node_modules":
			return filepath.SkipDir
		}
		return nil
	})
	if err != nil {
		return err
	}
	// Finally, set any unset status.
	return ctx.determinePackageStatus()
}
577108
func (builder *OnBuild) hasAssembleScript(config *api.Config) bool {
	assemblePath := filepath.Join(config.WorkingDir, "upload", "src", constants.Assemble)
	_, err := builder.fs.Stat(assemblePath)
	return err == nil
}
1159716
func Assemble(opts Options) error {
	var err error

	debug("createDirectories")
	err = createDirectories(opts)
	if err != nil {
		return err
	}

	debug("writeMeshbluConfig")
	err = writeMeshbluConfig(opts)
	if err != nil {
		return err
	}

	debug("writeServiceConfig")
	err = writeServiceConfig(opts)
	if err != nil {
		return err
	}

	debug("installIgnition")
	err = installIgnition(opts)
	if err != nil {
		return err
	}

	debug("foreverize")
	err = foreverize(opts)
	if err != nil {
		return err
	}

	return nil
}
998394
func (p *Imports) Bind(opts libs.SassOptions) {
	entries := make([]libs.ImportEntry, p.Len())
	i := 0

	p.RLock()
	for _, ent := range p.m {
		bs := ent.bytes
		entries[i] = libs.ImportEntry{
			Parent: ent.Prev,
			Path:   ent.Path,
			Source: string(bs),
		}
		i++
	}
	p.RUnlock()

	resolver := func(url string, prev string) (newURL string, body string, resolved bool) {
		if p.resolver != nil {
			newURL, body, resolved = p.resolver(url, prev)
			if resolved {
				return
			}
		}
		entry, err := libs.GetEntry(entries, prev, url)
		if err == nil {
			return url, entry, true
		}
		return "", "", false
	}

	// set entries somewhere so GC doesn't collect it
	p.idx = libs.BindImporter(opts, resolver)
}
541032
func (v *RsyncVolume) Import(label string, reader io.Reader) error {
	v.Lock()
	defer v.Unlock()
	label = v.rawSnapshotLabel(label)
	if exists, err := volume.IsDir(v.snapshotPath(label)); err != nil {
		return err
	} else if exists {
		return volume.ErrSnapshotExists
	}
	driverfile := fmt.Sprintf("%s-driver", label)
	volumedir := fmt.Sprintf("%s-volume", label)
	metadatadir := fmt.Sprintf("%s-metadata", label)
	var drivertype string
	tarfile := tar.NewReader(reader)
	for {
		header, err := tarfile.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			glog.Errorf("Could not import archive: %s", err)
			return err
		}
		if header.Name == driverfile {
			buf := bytes.NewBufferString("")
			if _, err := buf.ReadFrom(tarfile); err != nil {
				return err
			}
			drivertype = buf.String()
		} else if strings.HasPrefix(header.Name, volumedir) {
			header.Name = strings.Replace(header.Name, volumedir, label, 1)
			if err := volume.ImportArchiveHeader(header, tarfile, v.driver.Root()); err != nil {
				return err
			}
		} else if strings.HasPrefix(header.Name, metadatadir) {
			header.Name = strings.Replace(header.Name, metadatadir, label, 1)
			if err := volume.ImportArchiveHeader(header, tarfile, v.driver.MetadataDir()); err != nil {
				return err
			}
		}
	}
	if drivertype == "" {
		return errors.New("incompatible snapshot")
	}
	return nil
}
1019395
func (sd structDef) Imports() []string {
	ip := map[string]struct{}{}

	if sd.needFmt() {
		ip[`"fmt"`] = struct{}{}
	}
	if sd.OneLineDef == "" {
		ip[`"gopkg.in/validator.v2"`] = struct{}{}
	}

	// libraries
	for _, fd := range sd.Fields {
		if fd.fieldType == "json.RawMessage" {
			ip[`"encoding/json"`] = struct{}{}
		} else if lib := libImportPath(globRootImportPath, fd.fieldType, globLibRootURLs); lib != "" {
			ip[lib] = struct{}{}
		}
	}
	return commons.MapToSortedStrings(ip)
}
897586
func Import(ctx context.Context, c *vim25.Client, name string, datastore *object.Datastore, p ImportParams) error {
	m := ovf.NewManager(c)
	fm := datastore.NewFileManager(p.Datacenter, p.Force)

	disk, err := stat(name)
	if err != nil {
		return err
	}

	var rename string

	p.Path = strings.TrimSuffix(p.Path, "/")
	if p.Path != "" {
		disk.ImportName = p.Path
		rename = path.Join(disk.ImportName, disk.Name)
	}

	// "target" is the path that will be created by ImportVApp()
	// ImportVApp uses the same name for the VM and the disk.
	target := fmt.Sprintf("%s/%s.vmdk", disk.ImportName, disk.ImportName)

	if _, err = datastore.Stat(ctx, target); err == nil {
		if p.Force {
			// If we don't delete, the nfc upload adds a file name suffix
			if err = fm.Delete(ctx, target); err != nil {
				return err
			}
		} else {
			return fmt.Errorf("%s: %s", os.ErrExist, datastore.Path(target))
		}
	}

	// If we need to rename at the end, check if the file exists early unless Force.
	if !p.Force && rename != "" {
		if _, err = datastore.Stat(ctx, rename); err == nil {
			return fmt.Errorf("%s: %s", os.ErrExist, datastore.Path(rename))
		}
	}

	// Expand the ovf template
	descriptor, err := disk.ovf()
	if err != nil {
		return err
	}

	pool := p.Pool     // TODO: use datastore to derive a default
	folder := p.Folder // TODO: use datacenter to derive a default

	kind := p.Type
	if kind == "" {
		kind = types.VirtualDiskTypeThin
	}

	params := types.OvfCreateImportSpecParams{
		DiskProvisioning: string(kind),
		EntityName:       disk.ImportName,
	}

	spec, err := m.CreateImportSpec(ctx, descriptor, pool, datastore, params)
	if err != nil {
		return err
	}
	if spec.Error != nil {
		return errors.New(spec.Error[0].LocalizedMessage)
	}

	lease, err := pool.ImportVApp(ctx, spec.ImportSpec, folder, p.Host)
	if err != nil {
		return err
	}

	info, err := lease.Wait(ctx, spec.FileItem)
	if err != nil {
		return err
	}

	f, err := os.Open(filepath.Clean(name))
	if err != nil {
		return err
	}

	opts := soap.Upload{
		ContentLength: disk.Size,
		Progress:      p.Logger,
	}

	u := lease.StartUpdater(ctx, info)
	defer u.Done()

	item := info.Items[0] // we only have 1 disk to upload

	err = lease.Upload(ctx, item, f, opts)
	if err != nil {
		return err
	}

	err = f.Close()
	if err != nil {
		return err
	}

	if err = lease.Complete(ctx); err != nil {
		return err
	}

	// ImportVApp created a VM, here we detach the vmdk, then delete the VM.
	vm := object.NewVirtualMachine(c, info.Entity)

	device, err := vm.Device(ctx)
	if err != nil {
		return err
	}

	device = device.SelectByType((*types.VirtualDisk)(nil))

	err = vm.RemoveDevice(ctx, true, device...)
	if err != nil {
		return err
	}

	task, err := vm.Destroy(ctx)
	if err != nil {
		return err
	}

	if err = task.Wait(ctx); err != nil {
		return err
	}

	if rename == "" {
		return nil
	}

	return fm.Move(ctx, target, rename)
}
273451
func appendImports(i, a []*ImportSpec) []*ImportSpec {
	for _, v := range a {
		contains := false
		for _, att := range i {
			if att.Path == v.Path {
				contains = true
				break
			}
		}
		if contains != true {
			i = append(i, v)
		}
	}
	return i
}
987918
func (s service) Imports() []string {
	if !s.UnmarshallResponse {
		return nil
	}

	ipMap := map[string]struct{}{
		"from .unmarshall_error import UnmarshallError":      struct{}{},
		"from .unhandled_api_error import UnhandledAPIError": struct{}{},
	}
	for _, m := range s.Methods {
		for _, importLine := range m.imports() {
			ipMap[importLine] = struct{}{}
		}
	}
	return commons.MapToSortedStrings(ipMap)
}
942637
func (s *GlobalStore) Import(r io.Reader) (n int, err error) {
	tr := tar.NewReader(r)

	for {
		hdr, err := tr.Next()
		if err != nil {
			if err == io.EOF {
				break
			}
			return n, err
		}

		data, err := ioutil.ReadAll(tr)
		if err != nil {
			return n, err
		}

		var c mock.ExportedChunk
		if err = json.Unmarshal(data, &c); err != nil {
			return n, err
		}

		key := common.Hex2Bytes(hdr.Name)

		batch := new(leveldb.Batch)
		for _, addr := range c.Addrs {
			batch.Put(indexForHashesPerNode(addr, key), nil)
			batch.Put(indexForNodesWithHash(key, addr), nil)
			batch.Put(indexForNodes(addr), nil)
		}

		batch.Put(indexForHashes(key), nil)
		batch.Put(indexDataKey(key), c.Data)

		if err = s.db.Write(batch, nil); err != nil {
			return n, err
		}

		n++
	}
	return n, err
}
1036962
func (w *Wrapper) importDirsUsed() []string {
	used := []string{}
	for _, imp := range w.ImportDirs {
		for _, proto := range w.ProtoFiles {
			if strings.HasPrefix(proto, imp) {
				used = append(used, imp)
				break
			}
		}
	}
	return used
}
129266
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
	bctx := NewBuildContext(installSuffix, buildTags)
	pkg, err := bctx.ImportDir(dir, mode)
	if err != nil {
		return nil, err
	}

	jsFiles, err := jsFilesFromDir(bctx, pkg.Dir)
	if err != nil {
		return nil, err
	}

	return &PackageData{Package: pkg, JSFiles: jsFiles}, nil
}
218247
func ImportDirsUsed(importDirs []string, protos []string) []string {
	used := []string{}
	for _, imp := range importDirs {
		for _, proto := range protos {
			if strings.HasPrefix(proto, imp) {
				used = append(used, imp)
				break
			}
		}
	}
	return used
}
1200340
func (pc *class) Imports() []string {
	for _, field := range pc.Fields {
		for _, imp := range field.imports {
			// do not import ourself
			if imp.Name == pc.Name() {
				continue
			}
			pc.addImport(imp.Module, imp.Name)
		}
	}

	return commons.MapToSortedStrings(pc.imports)
}
1152008
func (s *cinderVolumeSource) ImportVolume(ctx context.ProviderCallContext, volumeId string, resourceTags map[string]string) (storage.VolumeInfo, error) {
	volume, err := s.storageAdapter.GetVolume(volumeId)
	if err != nil {
		common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
		return storage.VolumeInfo{}, errors.Annotate(err, "getting volume")
	}
	if volume.Status != volumeStatusAvailable {
		return storage.VolumeInfo{}, errors.Errorf(
			"cannot import volume %q with status %q", volumeId, volume.Status,
		)
	}
	if _, err := s.storageAdapter.SetVolumeMetadata(volumeId, resourceTags); err != nil {
		common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
		return storage.VolumeInfo{}, errors.Annotatef(err, "tagging volume %q", volumeId)
	}
	return cinderToJujuVolumeInfo(volume), nil
}