示例#1
0
int main(int argc, char *argv[])
{
	const char *s1 = "";
	const char *s2 = "";
	int ret;

	if(argc == 1) {
		usage();
		return 2;
	}
	if(argc > 1 &&
			(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0
			 || strcmp(argv[1], "--usage") == 0)) {
		usage();
		return 0;
	}
	if(argc > 2) {
		s2 = argv[2];
	}
	if(argc > 1) {
		s1 = argv[1];
	}

	ret = alpm_pkg_vercmp(s1, s2);
	printf("%d\n", ret);
	return EXIT_SUCCESS;
}
示例#2
0
static pmpkg_t *
alpm_pkg_find_update (pmpkg_t *pkg, const alpm_list_t *dbs)
{
	const gchar *name;
	const alpm_list_t *i;

	g_return_val_if_fail (pkg != NULL, NULL);

	name = alpm_pkg_get_name (pkg);

	for (; dbs != NULL; dbs = dbs->next) {
		pmpkg_t *update = alpm_db_get_pkg (dbs->data, name);

		if (update != NULL) {
			if (alpm_pkg_vercmp (alpm_pkg_get_version (update),
					     alpm_pkg_get_version (pkg)) > 0) {
				return update;
			} else {
				return NULL;
			}
		}

		i = alpm_db_get_pkgcache (dbs->data);
		for (; i != NULL; i = i->next) {
			if (alpm_list_find_str (alpm_pkg_get_replaces (i->data),
						name) != NULL) {
				return i->data;
			}
		}
	}

	return NULL;
}
示例#3
0
static gboolean
pk_alpm_pkg_is_local (PkBackendJob *job, alpm_pkg_t *pkg)
{
	PkBackend *backend = pk_backend_job_get_backend (job);
	PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
	alpm_pkg_t *local;

	g_return_val_if_fail (pkg != NULL, FALSE);

	/* find an installed package with the same name */
	local = alpm_db_get_pkg (priv->localdb, alpm_pkg_get_name (pkg));
	if (local == NULL)
		return FALSE;

	/* make sure the installed version is the same */
	if (alpm_pkg_vercmp (alpm_pkg_get_version (local),
			     alpm_pkg_get_version (pkg)) != 0) {
		return FALSE;
	}

	/* make sure the installed arch is the same */
	if (g_strcmp0 (alpm_pkg_get_arch (local),
		       alpm_pkg_get_arch (pkg)) != 0) {
		return FALSE;
	}

	return TRUE;
}
示例#4
0
static int pkgcomp(const void *a, const void *b)
{
    struct pkginfo *ap = *(struct pkginfo **)a;
    struct pkginfo *bp = *(struct pkginfo **)b;

    int namecomp = strcmp(ap->name, bp->name);

    return namecomp ? namecomp : -alpm_pkg_vercmp(ap->version,
            bp->version);
}
static gint
asb_package_alpm_compare (AsbPackage *pkg1, AsbPackage *pkg2)
{
	AsbPackageAlpm *pkg_alpm1 = ASB_PACKAGE_ALPM (pkg1);
	AsbPackageAlpmPrivate *priv1 = GET_PRIVATE (pkg_alpm1);

	AsbPackageAlpm *pkg_alpm2 = ASB_PACKAGE_ALPM (pkg2);
	AsbPackageAlpmPrivate *priv2 = GET_PRIVATE (pkg_alpm2);

	const gchar *pkg1_version = alpm_pkg_get_version (priv1->package);
	const gchar *pkg2_version = alpm_pkg_get_version (priv2->package);
	
	return alpm_pkg_vercmp (pkg1_version, pkg2_version);
}
示例#6
0
static inline alpm_pkghash_t *pkgcache_add(alpm_pkghash_t *cache, struct pkg *pkg)
{
    struct pkg *old = _alpm_pkghash_find(cache, pkg->name);
    int vercmp = old == NULL ? 0 : alpm_pkg_vercmp(pkg->version, old->version);

    if (vercmp == 0 || vercmp == 1) {
        if (old) {
            cache = _alpm_pkghash_remove(cache, old, NULL);
            package_free(old);
        }
        return _alpm_pkghash_add(cache, pkg);
    }

    return cache;
}
示例#7
0
int target_check_version (target_t *t, const char *ver)
{
	int ret;
	if (t->mod==ALPM_DEP_MOD_ANY) return 1;
	ret = alpm_pkg_vercmp (ver, t->ver);
	switch (t->mod)
	{
		case ALPM_DEP_MOD_LE: return (ret<=0);
		case ALPM_DEP_MOD_GE: return (ret>=0);
		case ALPM_DEP_MOD_LT: return (ret<0);
		case ALPM_DEP_MOD_GT: return (ret>0);
		case ALPM_DEP_MOD_EQ: return (ret==0);
		default: return 1;
	}
}
示例#8
0
bool target_check_version (const target_t *t, const char *ver)
{
	if (!t || !ver || t->mod == ALPM_DEP_MOD_ANY) {
		return true;
	}
	const int ret = alpm_pkg_vercmp (ver, t->ver);
	switch (t->mod)
	{
		case ALPM_DEP_MOD_LE: return (ret <= 0);
		case ALPM_DEP_MOD_GE: return (ret >= 0);
		case ALPM_DEP_MOD_LT: return (ret < 0);
		case ALPM_DEP_MOD_GT: return (ret > 0);
		case ALPM_DEP_MOD_EQ: return (ret == 0);
		default: return true;
	}
}
示例#9
0
static const char *color_print_aur_version (void *p, printpkgfn f, const char *i, const char *lver,
											 const char *ver)
{
	const char *info = NULL, *lver_color = NULL;
	if (!i) {
		lver_color = color(C_ORPHAN);
	} else {
		info = f(p, 'o');
		if (info && info[0] == '1') {
			lver_color = color(C_OD);
		}
	}
	fprintf (stdout, "%s%s%s", (lver_color) ? lver_color : color(C_VER), lver, color(C_NO));
	if (alpm_pkg_vercmp (ver, lver) > 0) {
		fprintf (stdout, " ( aur: %s )", ver);
	}
	fprintf (stdout, "\n");
	return info;
}
示例#10
0
文件: deps.c 项目: gtmanfred/pacman
static int dep_vercmp(const char *version1, alpm_depmod_t mod,
		const char *version2)
{
	int equal = 0;

	if(mod == ALPM_DEP_MOD_ANY) {
		equal = 1;
	} else {
		int cmp = alpm_pkg_vercmp(version1, version2);
		switch(mod) {
			case ALPM_DEP_MOD_EQ: equal = (cmp == 0); break;
			case ALPM_DEP_MOD_GE: equal = (cmp >= 0); break;
			case ALPM_DEP_MOD_LE: equal = (cmp <= 0); break;
			case ALPM_DEP_MOD_LT: equal = (cmp < 0); break;
			case ALPM_DEP_MOD_GT: equal = (cmp > 0); break;
			default: equal = 1; break;
		}
	}
	return equal;
}
示例#11
0
文件: sync.c 项目: Berticus/powaur
/* Normal -S, install packages from AUR
 * returns 0 on success, -1 on failure
 */
static int sync_targets(CURL *curl, alpm_list_t *targets)
{
	struct pw_hashdb *hashdb = build_hashdb();
	struct pkgpair pkgpair;
	struct pkgpair *pkgpair_ptr;
	struct aurpkg_t *aurpkg;
	alpm_pkg_t *lpkg;
	alpm_list_t *i;
	alpm_list_t *reinstall, *new_packages, *upgrade, *downgrade, *not_aur;
	alpm_list_t *aurpkg_list, *final_targets;
	int vercmp;
	int joined = 0, ret = 0;

	reinstall = new_packages = upgrade = downgrade = aurpkg_list = not_aur = NULL;
	final_targets = NULL;
	if (!hashdb) {
		pw_fprintf(PW_LOG_ERROR, stderr, "Failed to create hashdb\n");
		goto cleanup;
	}

	for (i = targets; i; i = i->next) {
		aurpkg_list = query_aur(curl, i->data, AUR_QUERY_INFO);
		if (!aurpkg_list) {
			not_aur = alpm_list_add(not_aur, i->data);
			goto free_aurpkg;
		}

		/* Check version string */
		pkgpair.pkgname = i->data;
		pkgpair_ptr = hash_search(hashdb->aur, &pkgpair);

		/* Locally installed AUR */
		if (pkgpair_ptr) {
			aurpkg = aurpkg_list->data;
			lpkg = pkgpair_ptr->pkg;
			vercmp = alpm_pkg_vercmp(aurpkg->version, alpm_pkg_get_version(lpkg));

			if (vercmp > 0) {
				upgrade = alpm_list_add(upgrade, i->data);
			} else if (vercmp == 0) {
				reinstall = alpm_list_add(reinstall, i->data);
			} else {
				downgrade = alpm_list_add(downgrade, i->data);
			}
		} else {
			new_packages = alpm_list_add(new_packages, i->data);
		}

free_aurpkg:
		alpm_list_free_inner(aurpkg_list, (alpm_list_fn_free) aurpkg_free);
		alpm_list_free(aurpkg_list);
	}

	if (not_aur) {
		printf("\n%sThese packages are not from the AUR:%s\n", color.bred, color.nocolor);
		print_list(not_aur);
	}

	if (downgrade) {
		printf("\n%sLocally installed but newer than AUR, ignoring:%s\n",
			   color.bcyan, color.nocolor);
		print_list(downgrade);
	}

	if (reinstall) {
		printf("\n%sReinstalling:%s\n", color.byellow, color.nocolor);
		print_list(reinstall);
	}

	if (upgrade) {
		printf("\n%sUpgrading:%s\n", color.bblue, color.nocolor);
		print_list(upgrade);
	}

	if (new_packages) {
		printf("\n%sSyncing:%s\n", color.bmag, color.nocolor);
		print_list(new_packages);
	}

	printf("\n");
	if (config->noconfirm || yesno("Do you wish to proceed?")) {
		final_targets = alpm_list_join(reinstall, upgrade);
		final_targets = alpm_list_join(final_targets, new_packages);
		joined = 1;
		ret = upgrade_pkgs(final_targets, hashdb);
	}

cleanup:
	hashdb_free(hashdb);
	alpm_list_free(downgrade);
	alpm_list_free(not_aur);

	if (joined) {
		alpm_list_free(final_targets);
	} else {
		alpm_list_free(reinstall);
		alpm_list_free(new_packages);
		alpm_list_free(upgrade);
	}

	return ret;
}
示例#12
0
文件: sync.c 项目: Berticus/powaur
/* Returns a list of outdated AUR packages among targets or all AUR packages.
 * The list and the packages are to be freed by the caller.
 *
 * @param curl curl easy handle
 * @param targets list of strings (package names) that are _definitely_ AUR packages
 */
static alpm_list_t *get_outdated_pkgs(CURL *curl, struct pw_hashdb *hashdb,
									  alpm_list_t *targets)
{
	alpm_list_t *i;
	alpm_list_t *outdated_pkgs = NULL;
	alpm_list_t *pkglist, *targs;
	struct pkgpair pkgpair;
	struct pkgpair *pkgpair_ptr;
	struct aurpkg_t *aurpkg;
	const char *pkgname, *pkgver;

	if (targets) {
		targs = targets;
	} else {
		targs = NULL;
		alpm_list_t *tmp_targs = hash_to_list(hashdb->aur);
		for (i = tmp_targs; i; i = i->next) {
			pkgpair_ptr = i->data;
			targs = alpm_list_add(targs, (void *) pkgpair_ptr->pkgname);
		}
		alpm_list_free(tmp_targs);
	}

	for (i = targs; i; i = i->next) {
		pkglist = query_aur(curl, i->data, AUR_QUERY_INFO);
		if (!pkglist) {
			continue;
		}

		pkgpair.pkgname = i->data;
		pkgpair_ptr = hash_search(hashdb->aur, &pkgpair);
		if (!pkgpair_ptr) {
			/* Shouldn't happen */
			pw_fprintf(PW_LOG_ERROR, stderr, "Unable to find AUR package \"%s\""
					   "in hashdb!\n", i->data);
		}

		aurpkg = pkglist->data;
		pkgver = alpm_pkg_get_version(pkgpair_ptr->pkg);
		pkgname = i->data;

		if (alpm_pkg_vercmp(aurpkg->version, pkgver) > 0) {
			/* Just show outdated package for now */
			pw_printf(PW_LOG_INFO, "%s %s is outdated, %s%s%s%s is available\n",
					  pkgname, pkgver, color.bred, aurpkg->version,
					  color.nocolor, color.bold);

			/* Add to upgrade list */
			outdated_pkgs = alpm_list_add(outdated_pkgs, aurpkg);
			pkglist->data = NULL;
		} else if (config->verbose) {
			pw_printf(PW_LOG_INFO, "%s %s is up to date.\n", pkgname,
					  pkgver);
		}

		alpm_list_free_inner(pkglist, (alpm_list_fn_free) aurpkg_free);
		alpm_list_free(pkglist);
	}

	if (!targets) {
		alpm_list_free(targs);
	}
	return outdated_pkgs;
}
示例#13
0
void color_print_package (void * p, printpkgfn f)
{
	string_t *cstr;
	static int number=0;
	const char *info, *lver;
	char *ver=NULL;
	int aur=(f == aur_get_str);
	int grp=(f == alpm_grp_get_str);
	cstr=string_new ();

	/* Numbering list */
	if (config.numbering)
		cstr = string_fcat (cstr, "%s%d%s ",
		    color (C_NB), ++number, color (C_NO));

	/* repo/name */
	if (config.aur_foreign)
		info = f(p, 'r');
	else
		info = f(p, 's');
	if (info)
	{
		if (config.get_res) dprintf (FD_RES, "%s/", info);
		cstr = string_fcat (cstr, "%s%s/%s",
		    color_repo (info), info, color(C_NO));
	}
	info=f(p, 'n');
	if (config.get_res) dprintf (FD_RES, "%s\n", info);
	cstr = string_fcat (cstr, "%s%s%s ", color(C_PKG), info, color(C_NO));

	if (grp)
	{
		/* no more output for groups */
		fprintf (stdout, "%s\n", string_cstr (cstr));
		string_free (cstr);
		return;
	}

	/* Version
	 * different colors:
	 *   C_ORPHAN if package exists in AUR and is orphaned
	 *   C_OD if package exists and is out of date
	 *   C_VER otherwise
	 */
	lver = alpm_local_pkg_get_str (info, 'l');
	info = f(p, (config.aur_upgrades) ? 'V' : 'v');
	ver = STRDUP (info);
	info = (aur) ? f(p, 'm') : NULL;
	if (config.aur_foreign)
	{
		/* Compare foreign package with AUR */
		if (aur)
		{
			const char *lver_color = NULL;
			if (!info)
				lver_color=color(C_ORPHAN);
			else
			{
				info = f(p, 'o');
				if (info && info[0]=='1')
					lver_color=color(C_OD);
			}
			cstr = string_fcat (cstr, "%s%s%s",
			    (lver_color) ? lver_color : color(C_VER),
			    lver, color (C_NO));
			if (alpm_pkg_vercmp (ver, lver)>0)
				cstr = string_fcat (cstr, " ( aur: %s )", ver);
			fprintf (stdout, "%s\n", string_cstr (cstr));
			FREE (ver);
		}
		else
			fprintf (stdout, "%s %s%s%s\n", string_cstr (cstr),
				color(C_VER), lver, color(C_NO));
		string_free (cstr);
		return;
	}
	if (aur && !info)
		cstr = string_fcat (cstr, "%s%s%s", color(C_ORPHAN), ver, color (C_NO));
	else
		cstr = string_fcat (cstr, "%s%s%s", color(C_VER), ver, color (C_NO));

	/* show size */
	if (config.show_size)
	{
		info = f(p, 'r');
		if (info)
		{
			if (strcmp (info, "aur")!=0)
				cstr = string_fcat (cstr, " [%.2f M]",
				    (double) get_size_pkg (p) / (1024.0 * 1024));
		}
	}

	if (config.aur_upgrades)
	{
		fprintf (stdout, "%s\n", string_cstr (cstr));
		string_free (cstr);
		FREE (ver);
		return;
	}

	/* show groups */
	info = f(p, 'g');
	if (info)
	{
		cstr = string_fcat (cstr, " %s(%s)%s", color(C_GRP), info, color(C_NO));
	}

	/* show install information */
	if (lver)
	{
		info = f(p, 'r');
		if (info && strcmp (info, "local")!=0)
		{
			cstr = string_fcat (cstr, " %s[%s",
			    color(C_INSTALLED), _("installed"));
			if (strcmp (ver, lver)!=0)
			{
				cstr = string_fcat (cstr, ": %s%s%s%s",
				    color(C_LVER), lver, color (C_NO), color(C_INSTALLED));
			}
			cstr = string_fcat (cstr, "]%s", color(C_NO));
		}
	}
	/* ver no more needed */
	FREE (ver);

	/* Out of date status & votes */
	if (aur)
	{
		info = f(p, 'o');
		if (info && info[0]=='1')
		{
			cstr = string_fcat (cstr, " %s(%s)%s",
				color(C_OD), _("Out of Date"), color(C_NO));
		}
		info = f(p, 'w');
		if (info)
		{
			cstr = string_fcat (cstr, " %s(%s)%s",
			    color(C_VOTES), info, color(C_NO));
		}
	}

	/* Display computed string */
	fprintf (stdout, "%s\n", string_cstr (cstr));
	string_free (cstr);

	/* Description
	 * if -Q or -Sl or -Sg <target>, don't display description
	 */
	if (config.op != OP_SEARCH && config.op != OP_LIST_REPO_S) return;
	fprintf (stdout, "%s", color(C_DSC));
	indent (f(p, 'd'));
	fprintf (stdout, "%s", color(C_NO));
}