Example #1
0
// Generates a vendor.pri inside vendorDir using the information contained in the package file
// and the dependencies
func GenerateVendorPri(vendorDir string, pkg *common.PackageWrapper) error {
	depMap, err := common.LoadPackages(vendorDir)
	if err != nil {
		return err
	}

	var deps []*common.PackageWrapper
	for _, dep := range depMap {
		deps = append(deps, dep)
	}

	vendorPriFile := filepath.Join(vendorDir, core.Vendor+".pri")

	data := struct {
		VendorDir    string
		Package      *common.PackageWrapper
		Dependencies []*common.PackageWrapper
	}{
		vendorDir,
		pkg,
		deps,
	}

	return core.WriteTemplate(vendorPriFile, vendorPri, data)
}
Example #2
0
func (u *UninstallCommand) Run() error {

	packageName := u.fs.Arg(0)

	if packageName == "" {
		err := fmt.Errorf("Must supply a package to uninstall")
		u.Error(err)
		return err
	}

	dependencyMap, err := common.LoadPackages(u.vendorDir)
	if err != nil {
		u.Error(err)
		return err
	}

	toRemove, exists := dependencyMap[packageName]
	if !exists {
		err := fmt.Errorf("Package %s was not found", packageName)
		u.Error(err)
		return err
	}

	// Does the current directory contain a package file that needs updating?
	pkg, err := common.LoadPackage("")
	if err != nil && !os.IsNotExist(err) {
		u.Error(err)
		return err
	} else if err == nil {
		pkg.RemoveDependency(toRemove)
		if err := pkg.Save(); err != nil {
			u.Error(err)
			return err
		}
	}

	fmt.Println("Uninstalling", toRemove.Name)

	// Final step is to delete the dependency's directory. This should
	// be done last since after this step, the info about the package is
	// gone.

	if err := os.RemoveAll(toRemove.RootDir()); err != nil {
		u.Error(err)
		return err
	}

	// Cleanup empty leaf directories in parent dirs
	dir := path.Clean(toRemove.RootDir() + "/..")
	for dir != u.vendorDir {
		if _, empty := u.isEmpty(dir); empty {
			os.Remove(dir)
		}
		dir = path.Clean(dir + "/..")
	}

	// Regenerate vendor.pri
	if err := GenerateVendorPri(u.vendorDir, pkg); err != nil {
		u.Error(err)
		return err
	}

	return nil
}