Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use new API to generate the checksums when recomputing with pkg check
Baptiste Daroussin committed 10 years ago
commit 0cc416339a38f9e84d5ed069034ee659b2f8bee3
parent 27dbb6e
8 files changed +32 -43
modified libpkg/pkg.c
@@ -728,13 +728,13 @@ pkg_addrdep(struct pkg *pkg, const char *name, const char *origin, const char *v
}

int
-
pkg_addfile(struct pkg *pkg, const char *path, const char *sha256, bool check_duplicates)
+
pkg_addfile(struct pkg *pkg, const char *path, const char *sum, bool check_duplicates)
{
-
	return (pkg_addfile_attr(pkg, path, sha256, NULL, NULL, 0, 0, check_duplicates));
+
	return (pkg_addfile_attr(pkg, path, sum, NULL, NULL, 0, 0, check_duplicates));
}

int
-
pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sha256,
+
pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sum,
    const char *uname, const char *gname, mode_t perm, u_long fflags,
    bool check_duplicates)
{
@@ -763,8 +763,8 @@ pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sha256,
	pkg_file_new(&f);
	strlcpy(f->path, path, sizeof(f->path));

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

	if (uname != NULL)
		strlcpy(f->uname, uname, sizeof(f->uname));
@@ -1622,7 +1622,7 @@ pkg_test_filesum(struct pkg *pkg)
	assert(pkg != NULL);

	while (pkg_files(pkg, &f) == EPKG_OK) {
-
		if (f->sum[0] != '\0') {
+
		if (f->sum != NULL) {
			if (!pkg_checksum_validate_file(f->path, f->sum)) {
				pkg_emit_file_mismatch(pkg, f, f->sum);
				rc = EPKG_FATAL;
@@ -1641,22 +1641,20 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
	int64_t flatsize = 0;
	struct stat st;
	bool regular = false;
-
	char *sha256;
+
	char *sum;
	int rc = EPKG_OK;

	hl = kh_init_hardlinks();
	while (pkg_files(pkg, &f) == EPKG_OK) {
		if (lstat(f->path, &st) == 0) {
			regular = true;
-
			if (S_ISLNK(st.st_mode)) {
+
			sum = pkg_checksum_generate_file(f->path,
+
			    PKG_HASH_TYPE_SHA256_HEX);
+

+
			if (S_ISLNK(st.st_mode))
				regular = false;
-
				sha256 = pkg_checksum_symlink(f->path, NULL,
-
				    PKG_HASH_TYPE_SHA256_HEX);
-
			} else {
-
				sha256 = pkg_checksum_file(f->path,
-
				    PKG_HASH_TYPE_SHA256_HEX);
-
			}
-
			if (sha256 == NULL) {
+

+
			if (sum == NULL) {
				rc = EPKG_FATAL;
				break;
			}
@@ -1667,9 +1665,9 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
			if (regular)
				flatsize += st.st_size;
		}
-
		if (strcmp(sha256, f->sum) != 0)
-
			pkgdb_file_set_cksum(db, f, sha256);
-
		free(sha256);
+
		if (strcmp(sum, f->sum) != 0)
+
			pkgdb_file_set_cksum(db, f, sum);
+
		free(sum);
	}
	kh_destroy_hardlinks(hl);

modified libpkg/pkg_attributes.c
@@ -105,6 +105,7 @@ pkg_file_new(struct pkg_file **file)
void
pkg_file_free(struct pkg_file *file)
{
+
	free(file->sum);
	free(file);
}

modified libpkg/pkg_create.c
@@ -55,7 +55,6 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	struct pkg_dir	*dir = NULL;
	int		 ret;
	struct stat	 st;
-
	char		*sha256;
	int64_t		 flatsize = 0;
	int64_t		 nfiles;
	const char	*relocation;
@@ -99,23 +98,19 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,

		if (S_ISLNK(st.st_mode)) {

-
			if (file->sum[0] == '\0') {
-
				sha256 = pkg_checksum_symlink(fpath, root,
+
			if (file->sum == NULL) {
+
				file->sum = pkg_checksum_symlink(fpath, root,
				    PKG_HASH_TYPE_SHA256_HEX);
-
				if (sha256 == NULL)
+
				if (file->sum == NULL)
					return (EPKG_FATAL);
-
				strlcpy(file->sum, sha256, sizeof(file->sum));
-
				free(sha256);
			}
		}
		else {
-
			if (file->sum[0] == '\0') {
-
				sha256 = pkg_checksum_file(fpath,
+
			if (file->sum == NULL) {
+
				file->sum = pkg_checksum_file(fpath,
				    PKG_HASH_TYPE_SHA256_HEX);
-
				if (sha256 == NULL)
+
				if (file->sum == NULL)
					return (EPKG_FATAL);
-
				strlcpy(file->sum, sha256, sizeof(file->sum));
-
				free(sha256);
			}
		}

modified libpkg/pkg_delete.c
@@ -278,7 +278,7 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)

	/* Regular files and links */
	/* check sha256 */
-
	if (!force && file->sum[0] != '\0') {
+
	if (!force && file->sum != NULL) {
		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] == '/' ? "" : "/",
modified libpkg/pkg_manifest.c
@@ -1132,8 +1132,8 @@ pkg_emit_object(struct pkg *pkg, short flags)
			pkg_debug(4, "Emitting files");
			map = NULL;
			while (pkg_files(pkg, &file) == EPKG_OK) {
-
				if (file->sum[0] == '\0')
-
					file->sum[1] = '-';
+
				if (file->sum == NULL)
+
					file->sum = strdup("-");

				urlencode(file->path, &tmpsbuf);
				if (map == NULL)
modified libpkg/pkg_old.c
@@ -111,17 +111,12 @@ int
pkg_from_old(struct pkg *p)
{
	struct pkg_file *f = NULL;
-
	char *sha256;

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

	return (EPKG_OK);
modified libpkg/pkgdb.c
@@ -2575,7 +2575,7 @@ pkgdb_set2(struct pkgdb *db, struct pkg *pkg, ...)

int
pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file,
-
		     const char *sha256)
+
     const char *sum)
{
	sqlite3_stmt	*stmt = NULL;
	const char	 sql_file_update[] = ""
@@ -2588,7 +2588,7 @@ pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file,
		ERROR_SQLITE(db->sqlite, sql_file_update);
		return (EPKG_FATAL);
	}
-
	sqlite3_bind_text(stmt, 1, sha256, -1, SQLITE_STATIC);
+
	sqlite3_bind_text(stmt, 1, sum, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 2, file->path, -1, SQLITE_STATIC);

	if (sqlite3_step(stmt) != SQLITE_DONE) {
@@ -2597,7 +2597,7 @@ pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file,
		return (EPKG_FATAL);
	}
	sqlite3_finalize(stmt);
-
	strlcpy(file->sum, sha256, sizeof(file->sum));
+
	file->sum = strdup(sum);

	return (EPKG_OK);
}
modified libpkg/private/pkg.h
@@ -219,7 +219,7 @@ struct pkg_provide {
struct pkg_file {
	char		 path[MAXPATHLEN];
	int64_t		 size;
-
	char		 sum[SHA256_DIGEST_LENGTH * 2 + 1];
+
	char		*sum;
	char		 uname[MAXLOGNAME];
	char		 gname[MAXLOGNAME];
	mode_t		 perm;