// OpenPackageFiles reads all rpm packages with the .rpm suffix from the given
// directory on the file systems and returns a slice of pointers to the loaded
// packages.
542655
func OpenPackageFiles(path string) ([]*PackageFile, error) {
	// read directory
	dir, err := ioutil.ReadDir(path)
	if err != nil {
		return nil, err
	}

	// list *.rpm files
	files := make([]string, 0)
	for _, f := range dir {
		if strings.HasSuffix(f.Name(), ".rpm") {
			files = append(files, filepath.Join(path, f.Name()))
		}
	}

	// read packages
	packages := make([]*PackageFile, len(files))
	for i, f := range files {
		p, err := OpenPackageFile(f)
		if err != nil {
			return nil, err
		}

		packages[i] = p
	}

	return packages, nil
}
1021699
func (*RPM) Package(info nfpm.Info, w io.Writer) error {
	arch, ok := archToRPM[info.Arch]
	if ok {
		info.Arch = arch
	}
	info.Version = strings.Replace(info.Version, "-", "_", -1)
	_, err := exec.LookPath("rpmbuild")
	if err != nil {
		return fmt.Errorf("rpmbuild not present in $PATH")
	}
	temps, err := setupTempFiles(info)
	if err != nil {
		return err
	}
	if err = createTarGz(info, temps.Folder, temps.Source); err != nil {
		return err
	}
	if err = createSpec(info, temps.Spec); err != nil {
		return errors.Wrap(err, "failed to create rpm spec file")
	}

	var args = []string{
		"--verbose",
		"--define", fmt.Sprintf("_topdir %s", temps.Root),
		"--define", fmt.Sprintf("_tmppath %s/tmp", temps.Root),
		"--target", fmt.Sprintf("%s-unknown-%s", info.Arch, info.Platform),
		"-ba",
		"SPECS/" + info.Name + ".spec",
	}
	cmd := exec.Command("rpmbuild", args...) //nolint:gosec
	cmd.Dir = temps.Root
	out, err := cmd.CombinedOutput()
	if err != nil {
		var msg = "rpmbuild failed"
		if string(out) != "" {
			msg += ": " + string(out)
		}
		return errors.Wrap(err, msg)
	}

	rpm, err := os.Open(temps.RPM)
	if err != nil {
		return errors.Wrap(err, "failed open rpm file")
	}
	_, err = io.Copy(w, rpm)
	return errors.Wrap(err, "failed to copy rpm file to writer")
}
1004675
func CheckPackages(c context.Context, names []string, includeHidden bool) ([]string, error) {
	if len(names) == 0 {
		return nil, nil
	}

	pkgs := make([]*Package, len(names))
	for i, n := range names {
		pkgs[i] = &Package{Name: n}
	}

	if err := datastore.Get(c, pkgs); err != nil {
		merr, ok := err.(errors.MultiError)
		if !ok {
			return nil, transient.Tag.Apply(err)
		}
		existing := pkgs[:0]
		for i, pkg := range pkgs {
			switch err := merr[i]; {
			case err == nil:
				existing = append(existing, pkg)
			case err != datastore.ErrNoSuchEntity:
				return nil, errors.Annotate(err, "failed to fetch %q", pkg.Name).Tag(transient.Tag).Err()
			}
		}
		pkgs = existing
	}

	out := make([]string, 0, len(pkgs))
	for _, p := range pkgs {
		if !p.Hidden || includeHidden {
			out = append(out, p.Name)
		}
	}
	return out, nil
}
1162816
func allPackages(ctxt *build.Context, root, start string, ch chan<- string) {

	var wg sync.WaitGroup

	var walkDir func(dir string)
	walkDir = func(dir string) {
		// Avoid .foo, _foo, and testdata directory trees.
		base := path.Base(dir)
		if base == "" || base[0] == '.' || base[0] == '_' || base == "testdata" {
			return
		}

		pkg := util.PathTrimPrefix(dir, root)

		// Prune search if we encounter any of these import paths.
		switch pkg {
		case "builtin":
			return
		}

		if pkg != "" {
			ch <- pkg
		}

		ioLimit <- true
		files, _ := buildutil.ReadDir(ctxt, dir)
		<-ioLimit
		for _, fi := range files {
			fi := fi
			if fi.IsDir() {
				wg.Add(1)
				go func() {
					walkDir(buildutil.JoinPath(ctxt, dir, fi.Name()))
					wg.Done()
				}()
			}
		}
	}

	walkDir(start)
	wg.Wait()
}
98523
func buildCopyFiles(c *model.CommandConfig, app *harness.App, revel_paths *model.RevelContainer) (packageFolders []string, err error) {
	appImportPath, destPath := c.ImportPath, c.Build.TargetPath

	// Revel and the app are in a directory structure mirroring import path
	srcPath := filepath.Join(destPath, "src")
	destBinaryPath := filepath.Join(destPath, filepath.Base(app.BinaryPath))
	tmpRevelPath := filepath.Join(srcPath, filepath.FromSlash(model.RevelImportPath))
	if err = utils.CopyFile(destBinaryPath, app.BinaryPath); err != nil {
		return
	}
	utils.MustChmod(destBinaryPath, 0755)

	// Copy the templates  from the revel
	if err = utils.CopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel_paths.RevelPath, "conf"), nil); err != nil {
		return
	}
	if err = utils.CopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel_paths.RevelPath, "templates"), nil); err != nil {
		return
	}

	// Get the folders to be packaged
	packageFolders = strings.Split(revel_paths.Config.StringDefault("package.folders", "conf,public,app/views"), ",")
	for i, p := range packageFolders {
		// Clean spaces, reformat slash to filesystem
		packageFolders[i] = filepath.FromSlash(strings.TrimSpace(p))
	}

	if c.Build.CopySource {
		err = utils.CopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel_paths.BasePath, nil)
		if err != nil {
			return
		}
	} else {
		for _, folder := range packageFolders {
			err = utils.CopyDir(
				filepath.Join(srcPath, filepath.FromSlash(appImportPath), folder),
				filepath.Join(revel_paths.BasePath, folder),
				nil)
			if err != nil {
				return
			}
		}
	}

	return
}
512734
func (r *registry) loadFile(file *descriptor.FileDescriptorProto) {
	pkg := &GoPackage{
		Path: r.goPackagePath(file),
		Name: defaultGoPackageName(file),
	}
	if err := r.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil {
		for i := 0; ; i++ {
			alias := fmt.Sprintf("%s_%d", pkg.Name, i)
			if err := r.ReserveGoPackageAlias(alias, pkg.Path); err == nil {
				pkg.Alias = alias
				break
			}
		}
	}
	f := &File{
		FileDescriptorProto: file,
		GoPackage:           pkg,
	}
	r.files[file.GetName()] = f
	r.registerMsg(f, nil, file.GetMessageType())
	r.registerEnum(f, nil, file.GetEnumType())
}
1360983
func (s *Layer) SetPackages(v []*string) *Layer {
	s.Packages = v
	return s
}
569605
func DeployPackage(resourcepaths []string, opts *ForceDeployOptions) {
	force, _ := ActiveForce()
	for _, name := range resourcepaths {
		zipfile, err := ioutil.ReadFile(name)
		result, err := force.Metadata.DeployZipFile(force.Metadata.MakeDeploySoap(*opts), zipfile)
		byName := false
		namePaths := make(map[string]string)
		err = processDeployResults(result, byName, namePaths, err)
		if err != nil {
			ErrorAndExit(err.Error())
		}
	}
	return
}
598368
func OpenFile(path string) (Sections, error) {
	f, err := os.Open(path)
	if err != nil {
		return Sections{}, awserr.New(ErrCodeUnableToReadFile, "unable to open file", err)
	}
	defer f.Close()

	return Parse(f)
}
465225
func (c *PackageFile) Files() []FileInfo {
	if c.files != nil {
		return c.files
	}

	ixs := c.GetInts(1, 1116)
	names := c.GetStrings(1, 1117)
	dirs := c.GetStrings(1, 1118)
	modes := c.GetInts(1, 1030)
	sizes := c.GetInts(1, 1028)
	times := c.GetInts(1, 1034)
	owners := c.GetStrings(1, 1039)
	groups := c.GetStrings(1, 1040)
	digests := c.GetStrings(1, 1035)
	linknames := c.GetStrings(1, 1036)

	c.files = make([]FileInfo, len(names))
	for i := 0; i < len(names); i++ {
		c.files[i] = FileInfo{
			name:     dirs[ixs[i]] + names[i],
			mode:     fileModeFromInt64(modes[i]),
			size:     sizes[i],
			modTime:  time.Unix(times[i], 0),
			owner:    owners[i],
			group:    groups[i],
			digest:   digests[i],
			linkname: linknames[i],
		}
	}

	return c.files
}
695611
func (g *Generator) loadPackage(path string) (*loader.PackageInfo, error) {
	pkg := g.Program.Package(path)
	if pkg != nil {
		return pkg, nil
	}

	return nil, fmt.Errorf("failed to load package %q", path)
}
582731
func listPackages(dir string) (directories []string) {
	// add subdirectories
	files, err := ioutil.ReadDir(dir)
	if err != nil {
		complete.Log("failed reading directory %s: %s", dir, err)
		return
	}

	// build paths array
	paths := make([]string, 0, len(files)+1)
	for _, f := range files {
		if f.IsDir() {
			paths = append(paths, filepath.Join(dir, f.Name()))
		}
	}
	paths = append(paths, dir)

	// import packages according to given paths
	for _, p := range paths {
		pkg, err := build.ImportDir(p, 0)
		if err != nil {
			complete.Log("failed importing directory %s: %s", p, err)
			continue
		}
		directories = append(directories, pkg.Dir)
	}
	return
}
1272295
func (p *Parser) ParsePackageFiles(fileNames []string) (*PackageInfo, error) {
	return p.parsePackage(".", fileNames, nil)
}
1180237
func rpmDataFromImageFS(image pkgutil.Image) (map[string]util.PackageInfo, error) {
	dbPath, err := rpmEnvCheck(image.FSPath)
	if err != nil {
		logrus.Warnf("Couldn't find RPM database: %s", err.Error())
		return nil, err
	}
	return rpmDataFromFS(image.FSPath, dbPath)
}
144055
func (c *Client) ListPackages(filter *Filter) ([]Package, error) {
	var resp []Package
	req := request{
		method: client.GET,
		url:    apiPackages,
		filter: filter,
		resp:   &resp,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to get list of packages")
	}
	return resp, nil
}
1306003
func (c *Client) UpdatePackages() (string, error) {
	stdout, stderr, err := c.execNpm("update")
	if err != nil {
		return stdout, errors.New(stderr)
	}
	return stdout, nil
}
925881
func (t *ImportTracker) TrackPackages(pkgs ...*types.Package) {
	for _, pkg := range pkgs {
		t.Imported[pkg.Path()] = pkg.Name()
	}
}