Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg_file is only used internally no need for accessors for other cases pkg_printf is enough
Baptiste Daroussin committed 11 years ago
commit 7e21f29be3f76353523588c4768e81e472df1d0b
parent fba771d
15 files changed +52 -122
modified libpkg/libpkg.ver
@@ -61,8 +61,6 @@ global:
	pkg_event_register;
	pkg_fetch_file;
	pkg_fetch_file_tmp;
-
	pkg_file_get;
-
	pkg_file_mode;
	pkg_files;
	pkg_finish_repo;
	pkg_fprintf;
modified libpkg/pkg.c
@@ -739,10 +739,10 @@ pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sha256, const ch
		HASH_FIND_STR(pkg->files, path, f);
		if (f != NULL) {
			if (pkg_object_bool(pkg_config_get("DEVELOPER_MODE"))) {
-
				pkg_emit_error("duplicate file listing: %s, fatal (developer mode)", pkg_file_path(f));
+
				pkg_emit_error("duplicate file listing: %s, fatal (developer mode)", f->path);
				return (EPKG_FATAL);
			} else {
-
				pkg_emit_error("duplicate file listing: %s, ignoring", pkg_file_path(f));
+
				pkg_emit_error("duplicate file listing: %s, ignoring", f->path);
				return (EPKG_OK);
			}
		}
@@ -1632,8 +1632,8 @@ pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
	}

	while (pkg_files(pkg, &file) == EPKG_OK) {
-
		snprintf(spath, sizeof(spath), "%s%s", src, pkg_file_path(file));
-
		snprintf(dpath, sizeof(dpath), "%s%s", dest, pkg_file_path(file));
+
		snprintf(spath, sizeof(spath), "%s%s", src, file->path);
+
		snprintf(dpath, sizeof(dpath), "%s%s", dest, file->path);
		packing_append_file_attr(pack, spath, dpath,
		    file->uname, file->gname, file->perm);
	}
@@ -1645,8 +1645,6 @@ int
pkg_test_filesum(struct pkg *pkg)
{
	struct pkg_file *f = NULL;
-
	const char *path;
-
	const char *sum;
	struct stat	 st;
	char sha256[SHA256_DIGEST_LENGTH * 2 + 1];
	int rc = EPKG_OK;
@@ -1654,24 +1652,22 @@ pkg_test_filesum(struct pkg *pkg)
	assert(pkg != NULL);

	while (pkg_files(pkg, &f) == EPKG_OK) {
-
		path = pkg_file_path(f);
-
		sum = pkg_file_cksum(f);
-
		if (*sum != '\0') {
-
			if (lstat(path, &st) == -1) {
+
		if (f->sum[0] != '\0') {
+
			if (lstat(f->path, &st) == -1) {
				pkg_emit_errno("pkg_create_from_dir", "lstat failed");
				return (EPKG_FATAL);
			}
			if (S_ISLNK(st.st_mode)) {
-
				if (pkg_symlink_cksum(path, NULL, sha256) != EPKG_OK)
+
				if (pkg_symlink_cksum(f->path, NULL, sha256) != EPKG_OK)
					return (EPKG_FATAL);
			}
			else {
-
				if (sha256_file(path, sha256) != EPKG_OK)
+
				if (sha256_file(f->path, sha256) != EPKG_OK)
					return (EPKG_FATAL);

			}
-
			if (strcmp(sha256, sum) != 0) {
-
				pkg_emit_file_mismatch(pkg, f, sum);
+
			if (strcmp(sha256, f->sum) != 0) {
+
				pkg_emit_file_mismatch(pkg, f, f->sum);
				rc = EPKG_FATAL;
			}
		}
@@ -1684,26 +1680,22 @@ int
pkg_recompute(struct pkgdb *db, struct pkg *pkg)
{
	struct pkg_file *f = NULL;
-
	const char *path;
	struct hardlinks *hl = NULL;
	int64_t flatsize = 0;
	int64_t oldflatsize;
	struct stat st;
	bool regular = false;
-
	const char *sum;
	char sha256[SHA256_DIGEST_LENGTH * 2 + 1];
	int rc = EPKG_OK;

	while (pkg_files(pkg, &f) == EPKG_OK) {
-
		path = pkg_file_path(f);
-
		sum = pkg_file_cksum(f);
-
		if (lstat(path, &st) == 0) {
+
		if (lstat(f->path, &st) == 0) {
			regular = true;
			if (S_ISLNK(st.st_mode)) {
				regular = false;
				*sha256 = '\0';
			} else {
-
				if (sha256_file(path, sha256) != EPKG_OK) {
+
				if (sha256_file(f->path, sha256) != EPKG_OK) {
					rc = EPKG_FATAL;
					break;
				}
@@ -1715,7 +1707,7 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
			if (regular)
				flatsize += st.st_size;
		}
-
		if (strcmp(sha256, sum) != 0)
+
		if (strcmp(sha256, f->sum) != 0)
			pkgdb_file_set_cksum(db, f, sha256);
	}
	HASH_FREE(hl, free);
modified libpkg/pkg.h.in
@@ -288,13 +288,6 @@ typedef enum {
} pkg_dep_attr;

typedef enum {
-
	PKG_FILE_PATH = 0,
-
	PKG_FILE_SUM,
-
	PKG_FILE_UNAME,
-
	PKG_FILE_GNAME
-
} pkg_file_attr;
-

-
typedef enum {
	PKG_DIR_PATH = 0,
	PKG_DIR_UNAME,
	PKG_DIR_GNAME
@@ -894,14 +887,6 @@ const char *pkg_dep_get(struct pkg_dep const * const , const pkg_dep_attr);
#define pkg_dep_version(d) pkg_dep_get(d, PKG_DEP_VERSION)
bool pkg_dep_is_locked(struct pkg_dep const * const);

-
/* pkg_file */
-
const char *pkg_file_get(struct pkg_file const * const, const pkg_file_attr);
-
#define pkg_file_path(f) pkg_file_get(f, PKG_FILE_PATH)
-
#define pkg_file_cksum(f) pkg_file_get(f, PKG_FILE_SUM)
-
#define pkg_file_uname(f) pkg_file_get(f, PKG_FILE_UNAME)
-
#define pkg_file_gname(f) pkg_file_get(f, PKG_FILE_GNAME)
-
mode_t pkg_file_mode(struct pkg_file const * const);
-

bool pkg_has_dir(struct pkg *, const char *);
bool pkg_has_file(struct pkg *, const char *);
/* pkg_dir */
modified libpkg/pkg_attributes.c
@@ -107,38 +107,6 @@ pkg_file_free(struct pkg_file *file)
	free(file);
}

-
const char *
-
pkg_file_get(struct pkg_file const * const f, const pkg_file_attr attr)
-
{
-
	assert(f != NULL);
-

-
	switch (attr) {
-
	case PKG_FILE_PATH:
-
		return (f->path);
-
		break;
-
	case PKG_FILE_SUM:
-
		return (f->sum);
-
		break;
-
	case PKG_FILE_UNAME:
-
		return (f->uname);
-
		break;
-
	case PKG_FILE_GNAME:
-
		return (f->gname);
-
		break;
-
	default:
-
		return (NULL);
-
		break;
-
	}
-
}
-

-
mode_t
-
pkg_file_mode(struct pkg_file const * const f)
-
{
-
	assert(f != NULL);
-

-
	return (f->perm);
-
}
-

/*
 * Dir
 */
modified libpkg/pkg_create.c
@@ -68,11 +68,9 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	 * Get / compute size / checksum if not provided in the manifest
	 */
	while (pkg_files(pkg, &file) == EPKG_OK) {
-
		const char *pkg_path = pkg_file_path(file);
-
		const char *pkg_sum = pkg_file_cksum(file);

		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
-
		    relocation, pkg_path);
+
		    relocation, file->path);

		if (lstat(fpath, &st) == -1) {
			pkg_emit_error("file '%s' is missing", fpath);
@@ -88,7 +86,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,

		if (S_ISLNK(st.st_mode)) {

-
			if (pkg_sum == NULL || pkg_sum[0] == '\0') {
+
			if (file->sum[0] == '\0') {
				if (pkg_symlink_cksum(fpath, root, sha256) == EPKG_OK)
					strlcpy(file->sum, sha256, sizeof(file->sum));
				else
@@ -96,7 +94,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
			}
		}
		else {
-
			if (pkg_sum == NULL || pkg_sum[0] == '\0') {
+
			if (file->sum[0] == '\0') {
				if (pkg->type == PKG_OLD_FILE) {
					if (md5_file(fpath, sha256) != EPKG_OK)
						return (EPKG_FATAL);
@@ -143,12 +141,11 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	}

	while (pkg_files(pkg, &file) == EPKG_OK) {
-
		const char *pkg_path = pkg_file_path(file);

		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
-
		    relocation, pkg_path);
+
		    relocation, file->path);

-
		ret = packing_append_file_attr(pkg_archive, fpath, pkg_path,
+
		ret = packing_append_file_attr(pkg_archive, fpath, file->path,
		    file->uname, file->gname, file->perm);
		developer = pkg_object_bool(pkg_config_get("DEVELOPER_MODE"));
		if (developer && ret != EPKG_OK)
modified libpkg/pkg_delete.c
@@ -220,7 +220,6 @@ pkg_effective_rmdir(struct pkgdb *db, struct pkg *pkg)
void
pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)
{
-
	const char *sum = pkg_file_cksum(file);
	const char *path;
	const char *prefix_rel;
	struct stat st;
@@ -229,7 +228,7 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)

	pkg_open_root_fd(pkg);

-
	path = pkg_file_path(file);
+
	path = file->path;
	path++;

	pkg_get(pkg, PKG_PREFIX, &prefix_rel);
@@ -238,7 +237,7 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)

	/* Regular files and links */
	/* check sha256 */
-
	if (!force && sum[0] != '\0') {
+
	if (!force && file->sum[0] != '\0') {
		if (fstatat(pkg->rootfd, path, &st, AT_SYMLINK_NOFOLLOW) == -1) {
			pkg_emit_error("cannot stat %s%s%s: %s", pkg->rootpath,
			    pkg->rootpath[strlen(pkg->rootpath) - 1] == '/' ? "" : "/",
@@ -254,7 +253,7 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)
			if (sha256_fileat(pkg->rootfd, path, sha256) != EPKG_OK)
				return;
		}
-
		if (strcmp(sha256, sum)) {
+
		if (strcmp(sha256, file->sum)) {
			pkg_emit_error("%s%s%s fails original SHA256 "
				"checksum, not removing", pkg->rootpath,
				pkg->rootpath[strlen(pkg->rootpath) - 1] == '/' ? "" : "/",
modified libpkg/pkg_elf.c
@@ -121,7 +121,7 @@ add_shlibs_to_pkg(__unused void *actdata, struct pkg *pkg, const char *fpath,
			return (EPKG_OK);

		while (pkg_files(pkg, &file) == EPKG_OK) {
-
			filepath = pkg_file_path(file);
+
			filepath = file->path;
			if (strcmp(&filepath[strlen(filepath) - strlen(name)], name) == 0) {
				pkg_addshlib_required(pkg, name);
				return (EPKG_OK);
@@ -473,9 +473,9 @@ pkg_analyse_files(struct pkgdb *db, struct pkg *pkg, const char *stage)

	while (pkg_files(pkg, &file) == EPKG_OK) {
		if (stage != NULL)
-
			snprintf(fpath, sizeof(fpath), "%s/%s", stage, pkg_file_path(file));
+
			snprintf(fpath, sizeof(fpath), "%s/%s", stage, file->path);
		else
-
			strlcpy(fpath, pkg_file_path(file), sizeof(fpath));
+
			strlcpy(fpath, file->path, sizeof(fpath));

		ret = analyse_elf(pkg, fpath, add_shlibs_to_pkg, db);
		if (developer) {
modified libpkg/pkg_event.c
@@ -304,7 +304,7 @@ pipeevent(struct pkg_event *ev)
		    "}}",
		    ev->e_file_mismatch.pkg,
		    ev->e_file_mismatch.pkg,
-
		    sbuf_json_escape(buf, pkg_file_path(ev->e_file_mismatch.file)));
+
		    sbuf_json_escape(buf, ev->e_file_mismatch.file->path));
		break;
	case PKG_EVENT_PLUGIN_ERRNO:
		sbuf_printf(msg, "{ \"type\": \"ERROR_PLUGIN\", "
modified libpkg/pkg_manifest.c
@@ -841,7 +841,7 @@ pkg_emit_filelist(struct pkg *pkg, FILE *f)

	seq = NULL;
	while (pkg_files(pkg, &file) == EPKG_OK) {
-
		urlencode(pkg_file_path(file), &b);
+
		urlencode(file->path, &b);
		if (seq == NULL)
			seq = ucl_object_typed_new(UCL_ARRAY);
		ucl_array_append(seq, ucl_object_fromlstring(sbuf_data(b), sbuf_len(b)));
@@ -1067,16 +1067,14 @@ pkg_emit_object(struct pkg *pkg, short flags)
			pkg_debug(4, "Emitting files");
			map = NULL;
			while (pkg_files(pkg, &file) == EPKG_OK) {
-
				const char *pkg_sum = pkg_file_cksum(file);
+
				if (file->sum[0] == '\0')
+
					file->sum[1] = '-';

-
				if (pkg_sum == NULL || pkg_sum[0] == '\0')
-
					pkg_sum = "-";
-

-
				urlencode(pkg_file_path(file), &tmpsbuf);
+
				urlencode(file->path, &tmpsbuf);
				if (map == NULL)
					map = ucl_object_typed_new(UCL_OBJECT);
				ucl_object_insert_key(map,
-
				    ucl_object_fromstring(pkg_sum),
+
				    ucl_object_fromstring(file->sum),
				    sbuf_data(tmpsbuf), sbuf_len(tmpsbuf), true);
			}
			if (map)
modified libpkg/pkg_old.c
@@ -145,8 +145,8 @@ pkg_old_emit_content(struct pkg *pkg, char **dest)
		sbuf_printf(content,
		    "%s\n"
		    "@comment MD5:%s\n",
-
		     pkg_file_path(file) + 1,
-
		     pkg_file_cksum(file));
+
		     file->path + 1,
+
		     file->sum);
	}

	while (pkg_dirs(pkg, &dir) == EPKG_OK) {
@@ -183,14 +183,12 @@ pkg_to_old(struct pkg *p)
{
	struct pkg_file *f = NULL;
	char md5[MD5_DIGEST_LENGTH * 2 + 1];
-
	const char *sum;

	p->type = PKG_OLD_FILE;
	while (pkg_files(p, &f) == EPKG_OK) {
-
		sum = pkg_file_cksum(f);
-
		if (sum == NULL || sum[0] == '\0')
+
		if (f->sum[0] == '\0')
			continue;
-
		if (md5_file(pkg_file_path(f), md5) == EPKG_OK)
+
		if (md5_file(f->path, md5) == EPKG_OK)
			strlcpy(f->sum, md5, sizeof(f->sum));
	}

@@ -202,14 +200,12 @@ pkg_from_old(struct pkg *p)
{
	struct pkg_file *f = NULL;
	char sha256[SHA256_DIGEST_LENGTH * 2 + 1];
-
	const char *sum;

	p->type = PKG_INSTALLED;
	while (pkg_files(p, &f) == EPKG_OK) {
-
		sum = pkg_file_cksum(f);
-
		if (sum == NULL || sum[0] == '\0')
+
		if (f->sum[0] == '\0')
			continue;
-
		if (sha256_file(pkg_file_path(f), sha256) == EPKG_OK)
+
		if (sha256_file(f->path, sha256) == EPKG_OK)
			strlcpy(f->sum, sha256, sizeof(f->sum));
	}

modified libpkg/pkg_printf.c
@@ -1069,7 +1069,7 @@ format_file_group(struct sbuf *sbuf, const void *data, struct percent_esc *p)
{
	const struct pkg_file	*file = data;

-
	return (string_val(sbuf, pkg_file_gname(file), p));
+
	return (string_val(sbuf, file->gname, p));
}

/*
@@ -1080,7 +1080,7 @@ format_file_path(struct sbuf *sbuf, const void *data, struct percent_esc *p)
{
	const struct pkg_file	*file = data;

-
	return (string_val(sbuf, pkg_file_path(file), p));
+
	return (string_val(sbuf, file->path, p));
}

/*
@@ -1091,7 +1091,7 @@ format_file_perms(struct sbuf *sbuf, const void *data, struct percent_esc *p)
{
	const struct pkg_file	*file = data;

-
	return (mode_val(sbuf, pkg_file_mode(file), p));
+
	return (mode_val(sbuf, file->perm, p));
}

/*
@@ -1102,7 +1102,7 @@ format_file_sha256(struct sbuf *sbuf, const void *data, struct percent_esc *p)
{
	const struct pkg_file	*file = data;

-
	return (string_val(sbuf, pkg_file_cksum(file), p));
+
	return (string_val(sbuf, file->sum, p));
}

/*
@@ -1113,7 +1113,7 @@ format_file_user(struct sbuf *sbuf, const void *data, struct percent_esc *p)
{
	const struct pkg_file	*file = data;

-
	return (string_val(sbuf, pkg_file_uname(file), p));
+
	return (string_val(sbuf, file->uname, p));
}

/*
modified libpkg/pkgdb.c
@@ -1638,19 +1638,17 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int complete, int forced)
	 */

	while (pkg_files(pkg, &file) == EPKG_OK) {
-
		const char	*pkg_path = pkg_file_path(file);
-
		const char	*pkg_sum  = pkg_file_cksum(file);
		bool		permissive = false;
		bool		devmode = false;

-
		ret = run_prstmt(FILES, pkg_path, pkg_sum, package_id);
+
		ret = run_prstmt(FILES, file->path, file->sum, package_id);
		if (ret == SQLITE_DONE)
			continue;
		if (ret != SQLITE_CONSTRAINT) {
			ERROR_SQLITE(s, SQL(FILES));
			goto cleanup;
		}
-
		it = pkgdb_query_which(db, pkg_path, false);
+
		it = pkgdb_query_which(db, file->path, false);
		if (it == NULL) {
			ERROR_SQLITE(s, "pkg which");
			goto cleanup;
@@ -1660,7 +1658,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int complete, int forced)
		if (ret == EPKG_END) {
			/* Stray entry in the files table not related to
			   any known package: overwrite this */
-
			ret = run_prstmt(FILES_REPLACE, pkg_path, pkg_sum,
+
			ret = run_prstmt(FILES_REPLACE, file->path, file->sum,
					 package_id);
			pkgdb_it_free(it);
			if (ret == SQLITE_DONE)
@@ -1683,7 +1681,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int complete, int forced)
			pkg_emit_error("%s-%s conflicts with %s-%s"
					" (installs files into the same place). "
					" Problematic file: %s%s",
-
					name, version, name2, version2, pkg_path,
+
					name, version, name2, version2, file->path,
					permissive ? " ignored by permissive mode" : "");
			pkg_free(pkg2);
			if (!permissive) {
@@ -1694,7 +1692,7 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int complete, int forced)
			pkg_emit_error("%s-%s conflicts with %s-%s"
					" (installs files into the same place). "
					" Problematic file: %s ignored by forced mode",
-
					name, version, name2, version2, pkg_path);
+
					name, version, name2, version2, file->path);
			pkg_free(pkg2);
		}
		pkgdb_it_free(it);
@@ -2503,7 +2501,7 @@ pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file,
		return (EPKG_FATAL);
	}
	sqlite3_bind_text(stmt, 1, sha256, -1, SQLITE_STATIC);
-
	sqlite3_bind_text(stmt, 2, pkg_file_path(file), -1, SQLITE_STATIC);
+
	sqlite3_bind_text(stmt, 2, file->path, -1, SQLITE_STATIC);

	if (sqlite3_step(stmt) != SQLITE_DONE) {
		ERROR_SQLITE(db->sqlite, sql_file_update);
modified libpkg/rcscripts.c
@@ -58,8 +58,8 @@ pkg_start_stop_rc_scripts(struct pkg *pkg, pkg_rc_attr attr)
	len = strlen(rc_d_path);

	while (pkg_files(pkg, &file) == EPKG_OK) {
-
		if (strncmp(rc_d_path, pkg_file_path(file), len) == 0) {
-
			rcfile = pkg_file_path(file);
+
		if (strncmp(rc_d_path, file->path, len) == 0) {
+
			rcfile = file->path;
			rcfile += len;
			rc = strrchr(rcfile, '/');
			rc++;
modified src/event.c
@@ -773,8 +773,8 @@ event_callback(void *data, struct pkg_event *ev)
		break;
	case PKG_EVENT_FILE_MISMATCH:
		pkg = ev->e_file_mismatch.pkg;
-
		pkg_fprintf(stderr, "%n-%v: checksum mismatch for %S\n", pkg,
-
		    pkg, pkg_file_path(ev->e_file_mismatch.file));
+
		pkg_fprintf(stderr, "%n-%v: checksum mismatch for %Fn\n", pkg,
+
		    pkg, ev->e_file_mismatch.file);
		break;
	case PKG_EVENT_PLUGIN_ERRNO:
		warnx("%s: %s(%s): %s",
modified tests/lib/manifest.c
@@ -223,8 +223,7 @@ test_manifest(void)
	ATF_REQUIRE(i == 2);

	ATF_REQUIRE(pkg_files(p, &file) == EPKG_OK);
-
	ATF_REQUIRE(strcmp(pkg_file_path(file), "/usr/local/bin/foo") ==
-
				0);
+
	ATF_REQUIRE(strcmp(file->path, "/usr/local/bin/foo") == 0);
#if 0
	ATF_REQUIRE(strcmp(pkg_file_sha256(file),
				"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b")