Exemplo n.º 1
0
static void
test_dpkg_arch_varbuf_archqual(void)
{
	struct varbuf vb = VARBUF_INIT;

	varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_NONE));
	varbuf_end_str(&vb);
	test_str(vb.buf, ==, "");
	varbuf_reset(&vb);

	varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_EMPTY));
	varbuf_end_str(&vb);
	test_str(vb.buf, ==, "");
	varbuf_reset(&vb);

	varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_ALL));
	varbuf_end_str(&vb);
	test_str(vb.buf, ==, ":all");
	varbuf_reset(&vb);

	varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_WILDCARD));
	varbuf_end_str(&vb);
	test_str(vb.buf, ==, ":any");
	varbuf_reset(&vb);
}
Exemplo n.º 2
0
/**
 * Add a string representation of the package name to a varbuf.
 *
 * Works exactly like pkgbin_name() but acts on the varbuf instead of
 * returning a string. It NUL terminates the varbuf.
 *
 * @param vb      The varbuf struct to modify.
 * @param pkg     The package to consider.
 * @param pkgbin  The binary package instance to consider.
 * @param pnaw    When to display the architecture qualifier.
 */
void
varbuf_add_pkgbin_name(struct varbuf *vb,
                       const struct pkginfo *pkg, const struct pkgbin *pkgbin,
                       enum pkg_name_arch_when pnaw)
{
	varbuf_add_str(vb, pkg->set->name);
	if (pkgbin_name_needs_arch(pkgbin, pnaw))
		varbuf_add_archqual(vb, pkgbin->arch);
	varbuf_end_str(vb);
}
Exemplo n.º 3
0
/**
 * Return a string representation of the package name.
 *
 * The returned string must not be freed, and it's permanently allocated so
 * can be used as long as the non-freeing memory pool has not been freed.
 *
 * The pnaw parameter should be one of pnaw_never (never print arch),
 * pnaw_foreign (print arch for foreign packages only), pnaw_nonambig (print
 * arch for non ambiguous cases) or pnaw_always (always print arch),
 *
 * @param pkg     The package to consider.
 * @param pkgbin  The binary package instance to consider.
 * @param pnaw    When to display the architecture qualifier.
 *
 * @return The string representation.
 */
const char *
pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin,
            enum pkg_name_arch_when pnaw)
{
	if (!pkgbin_name_needs_arch(pkgbin, pnaw))
		return pkg->set->name;

	/* Cache the package name representation, for later reuse. */
	if (pkgbin->pkgname_archqual == NULL) {
		struct varbuf vb = VARBUF_INIT;

		varbuf_add_str(&vb, pkg->set->name);
		varbuf_add_archqual(&vb, pkgbin->arch);
		varbuf_end_str(&vb);

		pkgbin->pkgname_archqual = nfstrsave(vb.buf);

		varbuf_destroy(&vb);
	}

	return pkgbin->pkgname_archqual;
}
Exemplo n.º 4
0
const char *
pkg_infodb_get_file(const struct pkginfo *pkg, const struct pkgbin *pkgbin,
                    const char *filetype)
{
	static struct varbuf vb;
	enum pkg_infodb_format format;

	/* Make sure to always read and verify the format version. */
	format = pkg_infodb_get_format();

	varbuf_reset(&vb);
	varbuf_add_str(&vb, pkg_infodb_get_dir());
	varbuf_add_char(&vb, '/');
	varbuf_add_str(&vb, pkg->set->name);
	if (pkgbin->multiarch == PKG_MULTIARCH_SAME &&
	    format == PKG_INFODB_FORMAT_MULTIARCH)
		varbuf_add_archqual(&vb, pkgbin->arch);
	varbuf_add_char(&vb, '.');
	varbuf_add_str(&vb, filetype);
	varbuf_end_str(&vb);

	return vb.buf;
}