예제 #1
0
/**
 * hif_db_set_string:
 **/
gboolean
hif_db_set_string (HifDb *db,
		   HyPackage package,
		   const gchar *key,
		   const gchar *value,
		   GError **error)
{
	gboolean ret = TRUE;
	gchar *index_dir = NULL;
	gchar *index_file = NULL;

	g_return_val_if_fail (HIF_IS_DB (db), FALSE);
	g_return_val_if_fail (package != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);
	g_return_val_if_fail (value != NULL, FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	/* create the index directory */
	index_dir = hif_db_get_dir_for_package (package);
	if (index_dir == NULL) {
		ret = FALSE;
		g_set_error (error,
			     HIF_ERROR,
			     HIF_ERROR_FAILED,
			     "cannot create index for %s",
			     hif_package_get_id (package));
		goto out;
	}
	ret = hif_db_create_dir (index_dir, error);
	if (!ret)
		goto out;

	/* write the value */
	index_file = g_build_filename (index_dir, key, NULL);
	g_debug ("writing %s to %s", value, index_file);
	ret = g_file_set_contents (index_file, value, -1, error);
	if (!ret)
		goto out;
out:
	g_free (index_dir);
	g_free (index_file);
	return ret;
}
예제 #2
0
/**
 * hif_db_set_string:
 * @db: a #HifDb instance.
 * @package: A package to use as a reference
 * @key: Key name to save, e.g. "reason"
 * @value: Key data to save, e.g. "dep"
 * @error: A #GError, or %NULL
 *
 * Writes a data value to the yumdb 'database'.
 *
 * Returns: Returns: %TRUE for success, %FALSE otherwise
 *
 * Since: 0.1.0
 **/
gboolean
hif_db_set_string(HifDb *db,
           HifPackage *package,
           const gchar *key,
           const gchar *value,
           GError **error)
{
    HifDbPrivate *priv = GET_PRIVATE(db);
    g_autofree gchar *index_dir = NULL;
    g_autofree gchar *index_file = NULL;

    g_return_val_if_fail(HIF_IS_DB(db), FALSE);
    g_return_val_if_fail(package != NULL, FALSE);
    g_return_val_if_fail(key != NULL, FALSE);
    g_return_val_if_fail(value != NULL, FALSE);
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

    if (!priv->enabled)
        return TRUE;

    /* create the index directory */
    index_dir = hif_db_get_dir_for_package(db, package);
    if (index_dir == NULL) {
        g_set_error(error,
                    HIF_ERROR,
                    HIF_ERROR_FAILED,
                    "cannot create index for %s",
                    hif_package_get_package_id(package));
        return FALSE;
    }
    if (!hif_db_create_dir(index_dir, error))
        return FALSE;

    /* write the value */
    index_file = g_build_filename(index_dir, key, NULL);
    g_debug("writing %s to %s", value, index_file);
    return g_file_set_contents(index_file, value, -1, error);
}