Exemplo n.º 1
0
alpm_handle_t *
pk_backend_configure (const gchar *filename, GError **error)
{
	PkBackendConfig *config;
	alpm_handle_t *handle;
	GError *e = NULL;

	g_return_val_if_fail (filename != NULL, FALSE);

	g_debug ("reading config from %s", filename);
	config = pk_backend_config_new ();
	pk_backend_config_enter_section (config, "options");

	if (pk_backend_config_parse (config, filename, NULL, &e)) {
		handle = pk_backend_config_configure_alpm (config, &e);
	} else {
		handle = NULL;
	}

	pk_backend_config_free (config);
	if (e != NULL) {
		g_propagate_error (error, e);
		if (handle != NULL) {
			alpm_release (handle);
		}
		return NULL;
	} else {
		return handle;
	}
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	int ret;
	enum _alpm_errno_t err;

	setlocale(LC_ALL, "");
	strings_init();

	if (argc == 1) {
		cwr_fprintf(stderr, LOG_ERROR, "not enough arguments\n");
		exit(EXIT_FAILURE);
	}

	const command_t *cmd = find(argv[1]);
	if (!cmd) {
		cwr_fprintf(stderr, LOG_ERROR, "command %s not understood\n", argv[1]);
		exit(EXIT_FAILURE);
	}

	/* if ((ret = parse_options(argc, argv)) != 0) */
	/* 	return ret; */

	cwr_fprintf(stderr, LOG_DEBUG, "initializing alpm\n");
	pmhandle = alpm_initialize(PACMAN_ROOT, PACMAN_DBPATH, &err);
	if (!pmhandle) {
		cwr_fprintf(stderr, LOG_ERROR, "failed to initialize alpm library\n");
		goto finish;
	}

	ret = run(cmd, --argc, ++argv);

finish:
	alpm_release(pmhandle);
	return ret;
}
Exemplo n.º 3
0
Arquivo: expac.c Projeto: aissat/expac
static void expac_free(expac_t *expac)
{
  if(expac == NULL) {
    return;
  }

  alpm_release(expac->alpm);
}
Exemplo n.º 4
0
static void cleanup(int signum)
{
	if(handle && alpm_release(handle) == -1) {
		fprintf(stderr, "error releasing alpm\n");
	}

	exit(signum);
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	int retval = 1; /* default = false */
	alpm_handle_t *handle;
	alpm_errno_t err;
	alpm_pkg_t *pkg = NULL;
	const alpm_siglevel_t level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL;

	if(argc != 2) {
		fprintf(stderr, "testpkg (pacman) v" PACKAGE_VERSION "\n\n"
			"Test a pacman package for validity.\n\n"
			"Usage: testpkg <package file>\n");
		return 1;
	}

	handle = alpm_initialize(ROOTDIR, DBPATH, &err);
	if(!handle) {
		fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
		return 1;
	}

	/* let us get log messages from libalpm */
	alpm_option_set_logcb(handle, output_cb);

	/* set gpgdir to default */
	alpm_option_set_gpgdir(handle, GPGDIR);

	if(alpm_pkg_load(handle, argv[1], 1, level, &pkg) == -1
			|| pkg == NULL) {
		err = alpm_errno(handle);
		switch(err) {
			case ALPM_ERR_PKG_NOT_FOUND:
				printf("Cannot find the given file.\n");
				break;
			case ALPM_ERR_PKG_OPEN:
				printf("Cannot open the given file.\n");
				break;
			case ALPM_ERR_LIBARCHIVE:
			case ALPM_ERR_PKG_INVALID:
				printf("Package is invalid.\n");
				break;
			default:
				printf("libalpm error: %s\n", alpm_strerror(err));
				break;
		}
		retval = 1;
	} else {
		alpm_pkg_free(pkg);
		printf("Package is valid.\n");
		retval = 0;
	}

	if(alpm_release(handle) == -1) {
		fprintf(stderr, "error releasing alpm\n");
	}

	return retval;
}
Exemplo n.º 6
0
PyObject* pyalpm_release(PyObject *self, PyObject *args)
{
  AlpmHandle *pyhandle;
  if(!PyArg_ParseTuple(args, "O!", &AlpmHandleType, &pyhandle))
    return NULL;

  alpm_release(pyhandle->c_data);
  pyhandle->c_data = NULL;
  Py_RETURN_NONE;
}
Exemplo n.º 7
0
void ipacman_cleanup(void)
{
    //specialized for installer
    /*alpm_option_remove_cachedir(handle, "/PKGS");*/

	/* free alpm library resources */
	if(handle && alpm_release(handle) == -1) {
		printf("error releasing alpm library\n");
	}
}
Exemplo n.º 8
0
static void
asb_package_alpm_finalize (GObject *object)
{
	AsbPackageAlpm *pkg = ASB_PACKAGE_ALPM (object);
	AsbPackageAlpmPrivate *priv = GET_PRIVATE (pkg);

	/* TODO: handle errors */
	alpm_pkg_free (priv->package);
	alpm_release (priv->handle);

	G_OBJECT_CLASS (asb_package_alpm_parent_class)->finalize (object);
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
	int retval = 1; /* default = false */
	pmhandle_t *handle;
	enum _pmerrno_t err;
	pmpkg_t *pkg = NULL;

	if(argc != 2) {
		fprintf(stderr, "usage: %s <package file>\n", BASENAME);
		return 1;
	}

	handle = alpm_initialize(ROOTDIR, DBPATH, &err);
	if(!handle) {
		fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
		return 1;
	}

	/* let us get log messages from libalpm */
	alpm_option_set_logcb(handle, output_cb);

	if(alpm_pkg_load(handle, argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1
			|| pkg == NULL) {
		err = alpm_errno(handle);
		switch(err) {
			case PM_ERR_PKG_OPEN:
				printf("Cannot open the given file.\n");
				break;
			case PM_ERR_LIBARCHIVE:
			case PM_ERR_PKG_INVALID:
				printf("Package is invalid.\n");
				break;
			default:
				printf("libalpm error: %s\n", alpm_strerror(err));
				break;
		}
		retval = 1;
	} else {
		alpm_pkg_free(pkg);
		printf("Package is valid.\n");
		retval = 0;
	}

	if(alpm_release(handle) == -1) {
		fprintf(stderr, "error releasing alpm\n");
	}

	return retval;
}
Exemplo n.º 10
0
/** Free the resources.
 *
 * @param ret the return value
 */
static void cleanup(int ret)
{
	if(config) {
		/* free alpm library resources */
		if(config->handle && alpm_release(config->handle) == -1) {
			pm_printf(ALPM_LOG_ERROR, "error releasing alpm library\n");
		}

		config_free(config);
		config = NULL;
	}

	/* free memory */
	FREELIST(pm_targets);
	exit(ret);
}
Exemplo n.º 11
0
void
pk_backend_destroy (PkBackend *backend)
{
	PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
	pk_alpm_groups_destroy (backend);
	pk_alpm_destroy_databases (backend);

	if (priv->alpm != NULL) {
		if (alpm_trans_get_flags (priv->alpm) < 0)
			alpm_trans_release (priv->alpm);
		alpm_release (priv->alpm);
	}

	FREELIST (priv->syncfirsts);
	FREELIST (priv->holdpkgs);
	g_free (priv);
}
Exemplo n.º 12
0
void cleanup (int ret)
{
	static int cleaned=0;
	if (cleaned) return;
	cleaned=1;
	if (config.handle && alpm_release(config.handle) == -1)
		fprintf(stderr, "error releasing alpm library\n");
	FREELIST(targets);
	FREE (config.arch);
	FREE (config.aur_url);
	FREE (config.configfile);
	FREE (config.dbpath);
	FREE (config.rootdir);
	alpm_cleanup ();
	aur_cleanup ();
	color_cleanup ();
	exit (ret);
}
Exemplo n.º 13
0
int main(int argc, char *argv[]) {
  int ret = 1;
  alpm_handle_t *alpm;
  alpm_list_t *results = NULL, *i;

  alpm = alpm_init();
  if (!alpm) {
    return ret;
  }

  ret = parse_options(argc, argv, alpm);
  if (ret != 0) {
    goto finish;
  }

  /* ensure sane defaults */
  if (!dblist && !opt_localpkg) {
    opt_local = true;
    dblist = alpm_list_add(dblist, db_local);
  }

  results = gather_packages(alpm, targets);
  if (results == NULL) {
    ret = 1;
    goto finish;
  }

  for (i = results; i; i = alpm_list_next(i)) {
    alpm_pkg_t *pkg = i->data;
    ret += print_pkg(pkg, opt_format);
  }
  ret = !!ret; /* clamp to zero/one */

  if(opt_localpkg) {
    alpm_list_free_inner(results, (alpm_list_fn_free)alpm_pkg_free);
  }
  alpm_list_free(results);

finish:
  alpm_list_free(dblist);
  alpm_list_free(targets);
  alpm_release(alpm);
  return ret;
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
	int retval = 1; /* default = false */
	pmpkg_t *pkg = NULL;

	if(argc != 2) {
		fprintf(stderr, "usage: %s <package file>\n", BASENAME);
		return(1);
	}

	if(alpm_initialize() == -1) {
		fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
		return(1);
	}

	/* let us get log messages from libalpm */
	alpm_option_set_logcb(output_cb);

	if(alpm_pkg_load(argv[1], 1, &pkg) == -1 || pkg == NULL) {
		switch(pm_errno) {
			case PM_ERR_PKG_OPEN:
				printf("Cannot open the given file.\n");
				break;
			case PM_ERR_LIBARCHIVE:
			case PM_ERR_PKG_INVALID:
				printf("Package is invalid.\n");
				break;
			default:
				printf("libalpm error: %s\n", alpm_strerrorlast());
				break;
		}
		retval = 1;
	} else {
		alpm_pkg_free(pkg);
		printf("Package is valid.\n");
		retval = 0;
	}

	if(alpm_release() == -1) {
		fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
	}

	return(retval);
}
Exemplo n.º 15
0
static void
pk_backend_destroy_alpm (PkBackend *self)
{
	g_return_if_fail (self != NULL);

	if (alpm != NULL) {
		if (alpm_trans_get_flags (alpm) < 0) {
			alpm_trans_release (alpm);
		}
		alpm_release (alpm);

		alpm = NULL;
		backend = NULL;
	}

	FREELIST (syncfirsts);
	FREELIST (holdpkgs);
	g_free (xfercmd);
	xfercmd = NULL;
}
Exemplo n.º 16
0
static gboolean
asb_package_alpm_open (AsbPackage *pkg, const gchar *filename, GError **error)
{
	AsbPackageAlpm *pkg_alpm = ASB_PACKAGE_ALPM (pkg);
	AsbPackageAlpmPrivate *priv = GET_PRIVATE (pkg_alpm);

	alpm_errno_t alpm_error;

	/* initialize the alpm library */
	priv->handle = alpm_initialize ("/", "/tmp", &alpm_error);
	if (priv->handle == NULL) {
		g_set_error (error,
		             ASB_PLUGIN_ERROR,
		             ASB_PLUGIN_ERROR_FAILED,
		             "libalpm initialization failed %s (%u) for %s",
		             alpm_strerror (alpm_error),
		             alpm_error,
		             filename);
		return FALSE;
	}

	/* open the package */
	if (alpm_pkg_load (priv->handle, filename, TRUE, 0, &priv->package) == -1) {
		g_set_error (error,
		             ASB_PLUGIN_ERROR,
		             ASB_PLUGIN_ERROR_FAILED,
		             "Failed to load package %s : %s (%u)",
		             filename,
		             alpm_strerror (alpm_errno (priv->handle)),
		             alpm_errno (priv->handle));
		alpm_release (priv->handle);
		return FALSE;
	}

	asb_package_set_name (pkg, alpm_pkg_get_name (priv->package));
	asb_package_set_url (pkg, alpm_pkg_get_url (priv->package));
	asb_package_set_arch (pkg, alpm_pkg_get_arch (priv->package));
	asb_package_alpm_ensure_version (pkg, error);

	return TRUE;
}
Exemplo n.º 17
0
static void pacman_manager_finalize (GObject *object) {
	PacmanManagerPrivate *priv;
	
	g_return_if_fail (object != NULL);
	
	priv = PACMAN_MANAGER_GET_PRIVATE (PACMAN_MANAGER (object));
	if (priv->transaction != NULL) {
		g_object_unref (priv->transaction);
	}
	
	g_free (priv->clean_method);
	if (priv->transfer != NULL) {
		g_closure_unref (priv->transfer);
	}
	
	pacman_list_free_full (priv->hold_packages, g_free);
	pacman_list_free_full (priv->sync_firsts, g_free);
	
	pacman_manager = NULL;
	alpm_release ();
	
	G_OBJECT_CLASS (pacman_manager_parent_class)->finalize (object);
}
Exemplo n.º 18
0
static void cleanup(void)
{
	alpm_list_free(walked);
	alpm_list_free(provisions);
	alpm_release(handle);
}
Exemplo n.º 19
0
int main(int argc, char **argv)
{
	alpm_list_t *i;
	int ret = 0;

	if(!(config = parse_opts(argc, argv))) {
		ret = 1;
		goto cleanup;
	}

	if(checks == 0) {
		checks = CHECK_DEPENDS | CHECK_FILES;
	}

	if(!(handle = pu_initialize_handle_from_config(config))) {
		fprintf(stderr, "error: failed to initialize alpm.\n");
		ret = 1;
		goto cleanup;
	}

	localdb = alpm_get_localdb(handle);
	pkgcache = alpm_db_get_pkgcache(localdb);

	for(; optind < argc; ++optind) {
		if(load_pkg(argv[optind]) == NULL) { ret = 1; }
	}
	if(!isatty(fileno(stdin)) && errno != EBADF) {
		char *buf = NULL;
		size_t len = 0;
		ssize_t read;

		while((read = getdelim(&buf, &len, isep, stdin)) != -1) {
			if(buf[read - 1] == isep) { buf[read - 1] = '\0'; }
			if(load_pkg(buf) == NULL) { ret = 1; }
		}
		free(buf);
	}

	if(ret) { goto cleanup; }

	if(packages == NULL) {
		packages = alpm_list_copy(pkgcache);
		recursive = 0;
	} else if(recursive) {
		/* load [opt-]depends */
		alpm_list_t *i, *originals = alpm_list_copy(packages);
		for(i = originals; i; i = alpm_list_next(i)) {
			add_deps(i->data);
		}
		alpm_list_free(originals);
	}

	for(i = packages; i; i = alpm_list_next(i)) {
		int pkgerr = 0;
#define RUNCHECK(t, b) if((checks & t) && b != 0) { pkgerr = ret = 1; }
		RUNCHECK(CHECK_DEPENDS, check_depends(i->data));
		RUNCHECK(CHECK_OPT_DEPENDS, check_opt_depends(i->data));
		RUNCHECK(CHECK_FILES, check_files(i->data));
		RUNCHECK(CHECK_FILE_PROPERTIES, check_file_properties(i->data));
		RUNCHECK(CHECK_MD5SUM, check_md5sum(i->data));
		RUNCHECK(CHECK_SHA256SUM, check_sha256sum(i->data));
#undef RUNCHECK
		if(pkgerr && list_broken) { printf("%s\n", alpm_pkg_get_name(i->data)); }
	}

cleanup:
	alpm_list_free(packages);
	alpm_release(handle);
	pu_config_free(config);

	return ret;
}
Exemplo n.º 20
0
static void deallocate(void* ptr)
{
  if (ptr)
    alpm_release(ptr);
}