Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
New pkg_file_get()
Baptiste Daroussin committed 14 years ago
commit ea5f019028e9cf78bff00bdae256bb1b3ef3d9ef
parent 3daabbf
13 files changed +60 -42
modified libpkg/pkg.c
@@ -581,8 +581,8 @@ pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sha256, const ch
	assert(path != NULL && path[0] != '\0');

	while (pkg_files(pkg, &f) != EPKG_END) {
-
		if (!strcmp(path, pkg_file_path(f))) {
-
			pkg_emit_error("duplicate file listing: %s, ignoring", pkg_file_path(f));
+
		if (!strcmp(path, pkg_file_get(f, PKG_FILE_PATH))) {
+
			pkg_emit_error("duplicate file listing: %s, ignoring", pkg_file_get(f, PKG_FILE_PATH));
			return (EPKG_OK);
		}
	}
@@ -591,7 +591,7 @@ pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sha256, const ch
	strlcpy(f->path, path, sizeof(f->path));

	if (sha256 != NULL)
-
		strlcpy(f->sha256, sha256, sizeof(f->sha256));
+
		strlcpy(f->sum, sha256, sizeof(f->sum));

	if (uname != NULL)
		strlcpy(f->uname, uname, sizeof(f->uname));
@@ -1076,8 +1076,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, pkg_file_get(file, PKG_FILE_PATH));
+
		snprintf(dpath, sizeof(dpath), "%s%s", dest, pkg_file_get(file, PKG_FILE_PATH));
		printf("%s -> %s\n", spath, dpath);
		packing_append_file(pack, spath, dpath);
	}
modified libpkg/pkg.h
@@ -147,6 +147,13 @@ 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_DEPS = 0,
	PKG_RDEPS,
	PKG_LICENSES,
@@ -529,8 +536,7 @@ int pkg_emit_manifest(struct pkg *pkg, char **buf);
const char *pkg_dep_get(struct pkg_dep const * const , const pkg_dep_attr);

/* pkg_file */
-
const char *pkg_file_path(struct pkg_file *);
-
const char *pkg_file_sha256(struct pkg_file *);
+
const char *pkg_file_get(struct pkg_file const * const, const pkg_file_attr);

const char *pkg_dir_path(struct pkg_dir *);
int pkg_dir_try(struct pkg_dir *);
modified libpkg/pkg_attributes.c
@@ -70,15 +70,27 @@ pkg_file_free(struct pkg_file *file)
}

const char *
-
pkg_file_path(struct pkg_file *file)
+
pkg_file_get(struct pkg_file const * const f, const pkg_file_attr attr)
{
-
	return (file->path);
-
}
+
	assert(f != NULL);

-
const char *
-
pkg_file_sha256(struct pkg_file *file)
-
{
-
	return (file->sha256);
+
	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;
+
	}
}

/*
modified libpkg/pkg_create.c
@@ -33,13 +33,13 @@ pkg_create_from_dir(struct pkg *pkg, const char *root, struct packing *pkg_archi
	 */
	while (pkg_files(pkg, &file) == EPKG_OK) {
		if (root != NULL)
-
			snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_file_path(file));
+
			snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_file_get(file, PKG_FILE_PATH));
		else
-
			strlcpy(fpath, pkg_file_path(file), sizeof(fpath));
+
			strlcpy(fpath, pkg_file_get(file, PKG_FILE_PATH), sizeof(fpath));

-
		if ((pkg_file_sha256(file) == NULL || pkg_file_sha256(file)[0] == '\0') && lstat(fpath, &st) == 0 && !S_ISLNK(st.st_mode)) {
+
		if ((pkg_file_get(file, PKG_FILE_SUM) == NULL || pkg_file_get(file, PKG_FILE_SUM)[0] == '\0') && lstat(fpath, &st) == 0 && !S_ISLNK(st.st_mode)) {
			sha256_file(fpath, sha256);
-
			strlcpy(file->sha256, sha256, sizeof(file->sha256));
+
			strlcpy(file->sum, sha256, sizeof(file->sum));
		}

	}
@@ -54,11 +54,11 @@ pkg_create_from_dir(struct pkg *pkg, const char *root, struct packing *pkg_archi

	while (pkg_files(pkg, &file) == EPKG_OK) {
		if (root != NULL)
-
			snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_file_path(file));
+
			snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_file_get(file, PKG_FILE_PATH));
		else
-
			strlcpy(fpath, pkg_file_path(file), sizeof(fpath));
+
			strlcpy(fpath, pkg_file_get(file, PKG_FILE_PATH), sizeof(fpath));

-
		packing_append_file_attr(pkg_archive, fpath, pkg_file_path(file), file->uname, file->gname, file->perm);
+
		packing_append_file_attr(pkg_archive, fpath, pkg_file_get(file, PKG_FILE_PATH), file->uname, file->gname, file->perm);
	}

	while (pkg_dirs(pkg, &dir) == EPKG_OK) {
modified libpkg/pkg_delete.c
@@ -97,15 +97,15 @@ pkg_delete_files(struct pkg *pkg, int force)
		if (file->keep == 1)
			continue;

-
		path = pkg_file_path(file);
+
		path = pkg_file_get(file, PKG_FILE_PATH);

		/* Regular files and links */
		/* check sha256 */
-
		if (!force && pkg_file_sha256(file)[0] != '\0') {
+
		if (!force && pkg_file_get(file, PKG_FILE_SUM)[0] != '\0') {
			if (sha256_file(path, sha256) == -1) {
				pkg_emit_error("sha256 calculation failed for '%s'",
					  path);
-
			} else if (strcmp(sha256, pkg_file_sha256(file)) != 0) {
+
			} else if (strcmp(sha256, pkg_file_get(file, PKG_FILE_SUM)) != 0) {
				pkg_emit_error("%s fails original SHA256 checksum,"
							   " not removing", path);
				continue;
modified libpkg/pkg_elf.c
@@ -101,7 +101,7 @@ pkg_analyse_files(struct pkgdb *db, struct pkg *pkg)
		return (EPKG_FATAL);

	while (pkg_files(pkg, &file) == EPKG_OK)
-
		analyse_elf(db, pkg, pkg_file_path(file));
+
		analyse_elf(db, pkg, pkg_file_get(file, PKG_FILE_PATH));

	return (EPKG_OK);
}
modified libpkg/pkg_jobs.c
@@ -94,7 +94,7 @@ pkg_jobs_keep_files_to_del(struct pkg *p1, struct pkg *p2)

		f2 = NULL;
		while (pkg_files(p2, &f2)) {
-
			if (strcmp(pkg_file_path(f1), pkg_file_path(f2)) == 0) {
+
			if (strcmp(pkg_file_get(f1, PKG_FILE_PATH), pkg_file_get(f2, PKG_FILE_PATH)) == 0) {
				f1->keep = 1;
				break;
			}
modified libpkg/pkg_manifest.c
@@ -763,8 +763,8 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)
					yaml_document_add_scalar(&doc, NULL, __DECONST(yaml_char_t*, "files"), 5, YAML_PLAIN_SCALAR_STYLE),
					files);
		}
-
		urlencode(pkg_file_path(file), &tmpsbuf);
-
		manifest_append_kv(files, sbuf_data(tmpsbuf), pkg_file_sha256(file) && strlen(pkg_file_sha256(file)) > 0 ? pkg_file_sha256(file) : "-");
+
		urlencode(pkg_file_get(file, PKG_FILE_PATH), &tmpsbuf);
+
		manifest_append_kv(files, sbuf_data(tmpsbuf), pkg_file_get(file, PKG_FILE_SUM) && strlen(pkg_file_get(file, PKG_FILE_SUM)) > 0 ? pkg_file_get(file, PKG_FILE_SUM) : "-");
	}

	seq = -1;
modified libpkg/pkg_private.h
@@ -62,7 +62,7 @@ struct pkg_category {

struct pkg_file {
	char path[MAXPATHLEN +1];
-
	char sha256[SHA256_DIGEST_LENGTH * 2 +1];
+
	char sum[SHA256_DIGEST_LENGTH * 2 +1];
	char uname[MAXLOGNAME +1];
	char gname[MAXLOGNAME +1];
	int keep;
modified libpkg/pkgdb.c
@@ -1533,14 +1533,14 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int complete)
	}

	while (pkg_files(pkg, &file) == EPKG_OK) {
-
		sqlite3_bind_text(stmt_file, 1, pkg_file_path(file), -1, SQLITE_STATIC);
-
		sqlite3_bind_text(stmt_file, 2, pkg_file_sha256(file), -1, SQLITE_STATIC);
+
		sqlite3_bind_text(stmt_file, 1, pkg_file_get(file, PKG_FILE_PATH), -1, SQLITE_STATIC);
+
		sqlite3_bind_text(stmt_file, 2, pkg_file_get(file, PKG_FILE_SUM), -1, SQLITE_STATIC);
		sqlite3_bind_int64(stmt_file, 3, package_id);

		if ((ret = sqlite3_step(stmt_file)) != SQLITE_DONE) {
			if (ret == SQLITE_CONSTRAINT) {
				    pkg_emit_error("sqlite: constraint violation on files.path:"
-
								   " %s", pkg_file_path(file));
+
								   " %s", pkg_file_get(file, PKG_FILE_PATH));
			} else {
				ERROR_SQLITE(s);
			}
@@ -2618,13 +2618,13 @@ pkgdb_integrity_append(struct pkgdb *db, struct pkg *p)
		sqlite3_bind_text(stmt, 1, pkg_get(p, PKG_NAME), -1, SQLITE_STATIC);
		sqlite3_bind_text(stmt, 2, pkg_get(p, PKG_ORIGIN), -1, SQLITE_STATIC);
		sqlite3_bind_text(stmt, 3, pkg_get(p, PKG_VERSION), -1, SQLITE_STATIC);
-
		sqlite3_bind_text(stmt, 4, pkg_file_path(file), -1, SQLITE_STATIC);
+
		sqlite3_bind_text(stmt, 4, pkg_file_get(file, PKG_FILE_PATH), -1, SQLITE_STATIC);

		if (sqlite3_step(stmt) != SQLITE_DONE) {
			sbuf_clear(conflictmsg);
			sbuf_printf(conflictmsg, "WARNING: %s-%s conflict on %s with: \n",
					pkg_get(p, PKG_NAME), pkg_get(p, PKG_VERSION),
-
					pkg_file_path(file));
+
					pkg_file_get(file, PKG_FILE_PATH));

			if (sqlite3_prepare_v2(db->sqlite, sql_conflicts, -1, &stmt_conflicts, NULL) != SQLITE_OK) {
				ERROR_SQLITE(db->sqlite);
@@ -2633,7 +2633,7 @@ pkgdb_integrity_append(struct pkgdb *db, struct pkg *p)
				return (EPKG_FATAL);
			}

-
			sqlite3_bind_text(stmt_conflicts, 1, pkg_file_path(file), -1, SQLITE_STATIC);
+
			sqlite3_bind_text(stmt_conflicts, 1, pkg_file_get(file, PKG_FILE_PATH), -1, SQLITE_STATIC);

			while (sqlite3_step(stmt_conflicts) != SQLITE_DONE) {
				sbuf_printf(conflictmsg, "\t- %s-%s\n",
modified libpkg/rcscripts.c
@@ -26,8 +26,8 @@ pkg_stop_rc_scripts(struct pkg *pkg)
	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, pkg_file_get(file, PKG_FILE_PATH), len) == 0) {
+
			rcfile = pkg_file_get(file, PKG_FILE_PATH);
			rcfile += len;

			ret += rc_stop(rcfile);
@@ -50,8 +50,8 @@ pkg_start_rc_scripts(struct pkg *pkg)
	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, pkg_file_get(file, PKG_FILE_PATH), len) == 0) {
+
			rcfile = pkg_file_get(file, PKG_FILE_PATH);
			rcfile += len;

			ret += rc_start(rcfile);
modified pkg/query.c
@@ -151,9 +151,9 @@ format_str(struct pkg *pkg, struct sbuf *dest, const char *qstr, void *data)
				case 'F':
					qstr++;
					if (qstr[0] == 'p')
-
						sbuf_cat(dest, pkg_file_path((struct pkg_file *)data));
+
						sbuf_cat(dest, pkg_file_get((struct pkg_file *)data, PKG_FILE_PATH));
					else if (qstr[0] == 's')
-
						sbuf_cat(dest, pkg_file_sha256((struct pkg_file *)data));
+
						sbuf_cat(dest, pkg_file_get((struct pkg_file *)data, PKG_FILE_SUM));
					break;
				case 'S':
					sbuf_cat(dest, pkg_script_data((struct pkg_script *)data));	
modified pkg/utils.c
@@ -121,7 +121,7 @@ print_info(struct pkg * const pkg, unsigned int opt)
                        printf("%s-%s owns the following files:\n", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));

                while (pkg_files(pkg, &file) == EPKG_OK) {
-
                        printf("%s\n", pkg_file_path(file));
+
                        printf("%s\n", pkg_file_get(file, PKG_FILE_PATH));
                }

                if (!(opt & INFO_QUIET))