Example #1
0
/**
 * asb_package_ensure:
 * @pkg: A #AsbPackage
 * @flags: #AsbPackageEnsureFlags
 * @error: A #GError or %NULL
 *
 * Ensures data exists.
 *
 * Returns: %TRUE for success, %FALSE otherwise
 *
 * Since: 0.3.0
 **/
gboolean
asb_package_ensure (AsbPackage *pkg,
		    AsbPackageEnsureFlags flags,
		    GError **error)
{
	AsbPackageClass *klass = ASB_PACKAGE_GET_CLASS (pkg);
	AsbPackagePrivate *priv = GET_PRIVATE (pkg);

	/* reopen as required */
	if (!priv->is_open) {
		if (!asb_package_open (pkg, priv->filename, error))
			return FALSE;
	}

	/* this is recounted */
	if (flags & ASB_PACKAGE_ENSURE_DEPS)
		priv->deps_refcount++;
	if (flags & ASB_PACKAGE_ENSURE_FILES)
		priv->filelist_refcount++;

	/* clear flags */
	if (priv->name != NULL)
		flags &= ~ASB_PACKAGE_ENSURE_NEVRA;
	if (priv->license != NULL)
		flags &= ~ASB_PACKAGE_ENSURE_LICENSE;
	if (priv->vcs != NULL)
		flags &= ~ASB_PACKAGE_ENSURE_VCS;
	if (priv->url != NULL)
		flags &= ~ASB_PACKAGE_ENSURE_URL;
	if (priv->source_pkgname != NULL)
		flags &= ~ASB_PACKAGE_ENSURE_SOURCE;
	if (priv->filelist != NULL)
		flags &= ~ASB_PACKAGE_ENSURE_FILES;
	if (priv->deps->len > 0)
		flags &= ~ASB_PACKAGE_ENSURE_DEPS;
	if (priv->releases->len > 0)
		flags &= ~ASB_PACKAGE_ENSURE_RELEASES;

	/* nothing to do! */
	if (flags == ASB_PACKAGE_ENSURE_NONE)
		return TRUE;

	/* call distro-specific method */
	if (klass->ensure != NULL)
		return klass->ensure (pkg, flags, error);
	return TRUE;
}
Example #2
0
/**
 * asb_context_add_filename:
 * @ctx: A #AsbContext
 * @filename: package filename
 * @error: A #GError or %NULL
 *
 * Adds a filename to the list of packages to be processed
 *
 * Returns: %TRUE for success, %FALSE otherwise
 *
 * Since: 0.1.0
 **/
gboolean
asb_context_add_filename (AsbContext *ctx, const gchar *filename, GError **error)
{
	g_autoptr(AsbPackage) pkg = NULL;

	/* can find in existing metadata */
	if (asb_context_find_in_cache (ctx, filename)) {
		g_debug ("Found %s in old metadata", filename);
		return TRUE;
	}

	/* open */
#if HAVE_RPM
	if (g_str_has_suffix (filename, ".rpm"))
		pkg = asb_package_rpm_new ();
#endif
#if HAVE_ALPM
	if (g_str_has_suffix (filename, ".pkg.tar.xz"))
		pkg = asb_package_alpm_new ();
#endif
	if (g_str_has_suffix (filename, ".cab"))
		pkg = asb_package_cab_new ();
	if (g_str_has_suffix (filename, ".deb"))
		pkg = asb_package_deb_new ();
	if (pkg == NULL) {
		g_set_error (error,
			     ASB_PLUGIN_ERROR,
			     ASB_PLUGIN_ERROR_FAILED,
			     "No idea how to handle %s",
			     filename);
		return FALSE;
	}

	/* add to array */
	asb_package_set_filename (pkg, filename);

	/* failed to guess the nevra */
	if (asb_package_get_name (pkg) == NULL) {
		if (!asb_package_open (pkg, filename, error))
			return FALSE;
	}

	asb_context_add_package (ctx, pkg);
	return TRUE;
}