"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Tobias Heider <tobias.heider@stusta.de>
Subject:
Re: add an algo field to got_pack
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Thu, 11 Jul 2024 16:11:55 +0200

Download raw body.

Thread
On Thu, Jul 11, 2024 at 04:07:55PM +0200, Omar Polo wrote:
> This is the other one for pack_idx.  While here, already start to use
> the algo filed to avoid some hardcoded values.

ok, as discussed this will be convenient for some of the
planned future changes

> commit - 0f043da298c940db3fe16055dcebe4aba60d2834
> path + /home/op/w/got
> blob - 1b9a3c7d50834fc34fcac7ff7919ea96d024bf44
> file + lib/got_lib_pack.h
> --- lib/got_lib_pack.h
> +++ lib/got_lib_pack.h
> @@ -122,6 +122,7 @@ struct got_pack_large_offset_index {
>  struct got_packidx {
>  	char *path_packidx; /* actual on-disk path */
>  	int fd;
> +	enum got_hash_algorithm algo;
>  	uint8_t *map;
>  	size_t len;
>  	size_t nlargeobj;
> @@ -160,7 +161,7 @@ struct got_packfile_obj_hdr {
>  
>  const struct got_error *got_packidx_init_hdr(struct got_packidx *, int, off_t);
>  const struct got_error *got_packidx_open(struct got_packidx **,
> -    int, const char *, int);
> +    int, const char *, int, enum got_hash_algorithm);
>  const struct got_error *got_packidx_close(struct got_packidx *);
>  const struct got_error *got_packidx_get_packfile_path(char **, const char *);
>  off_t got_packidx_get_object_offset(struct got_packidx *, int idx);
> blob - a17be0408a103339d10ae1a1e9736deb19fb0b74
> file + lib/got_lib_privsep.h
> --- lib/got_lib_privsep.h
> +++ lib/got_lib_privsep.h
> @@ -513,6 +513,7 @@ struct got_imsg_index_pack_progress {
>  struct got_imsg_packidx {
>  	size_t len;
>  	off_t packfile_size;
> +	int algo;
>  	/* Additionally, a file desciptor is passed via imsg. */
>  };
>  
> blob - 84302f45b8db014cc23483d23a273c03f7fa077c
> file + lib/pack.c
> --- lib/pack.c
> +++ lib/pack.c
> @@ -75,7 +75,6 @@ const struct got_error *
>  got_packidx_init_hdr(struct got_packidx *p, int verify, off_t packfile_size)
>  {
>  	const struct got_error *err = NULL;
> -	enum got_hash_algorithm algo = GOT_HASH_SHA1;
>  	struct got_packidx_v2_hdr *h;
>  	struct got_hash ctx;
>  	uint8_t hash[GOT_HASH_DIGEST_MAXLEN];
> @@ -83,7 +82,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
>  	ssize_t n;
>  	int i;
>  
> -	got_hash_init(&ctx, algo);
> +	got_hash_init(&ctx, p->algo);
>  
>  	h = &p->hdr;
>  	offset = 0;
> @@ -183,7 +182,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
>  	remain -= len_fanout;
>  
>  	nobj = be32toh(h->fanout_table[0xff]);
> -	len_ids = nobj * sizeof(*h->sorted_ids);
> +	len_ids = nobj * got_hash_digest_length(p->algo);
>  	if (len_ids <= nobj || len_ids > remain) {
>  		err = got_error(GOT_ERR_BAD_PACKIDX);
>  		goto done;
> @@ -327,7 +326,7 @@ checksum:
>  	}
>  	if (verify) {
>  		got_hash_update(&ctx, h->trailer->packfile_sha1,
> -		    SHA1_DIGEST_LENGTH);
> +		    got_hash_digest_length(p->algo));
>  		got_hash_final(&ctx, hash);
>  		if (got_hash_cmp(ctx.algo, hash, h->trailer->packidx_sha1) != 0)
>  			err = got_error(GOT_ERR_PACKIDX_CSUM);
> @@ -338,7 +337,8 @@ done:
>  
>  const struct got_error *
>  got_packidx_open(struct got_packidx **packidx,
> -    int dir_fd, const char *relpath, int verify)
> +    int dir_fd, const char *relpath, int verify,
> +    enum got_hash_algorithm algo)
>  {
>  	const struct got_error *err = NULL;
>  	struct got_packidx *p = NULL;
> @@ -371,6 +371,8 @@ got_packidx_open(struct got_packidx **packidx,
>  		goto done;
>  	}
>  
> +	p->algo = algo;
> +
>  	p->fd = openat(dir_fd, relpath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
>  	if (p->fd == -1) {
>  		err = got_error_from_errno2("openat", relpath);
> blob - 8aa0ad08ca44ef4b71ccf60df2cf2b962c13da78
> file + lib/pack_index.c
> --- lib/pack_index.c
> +++ lib/pack_index.c
> @@ -211,7 +211,7 @@ read_packed_object(struct got_pack *pack, struct got_i
>  		}
>  		if (err)
>  			break;
> -		got_hash_init(&ctx, GOT_HASH_SHA1);
> +		got_hash_init(&ctx, pack->algo);
>  		err = got_object_type_label(&obj_label, obj->type);
>  		if (err) {
>  			free(data);
> @@ -414,7 +414,7 @@ resolve_deltified_object(struct got_pack *pack, struct
>  		goto done;
>  	}
>  	headerlen = strlen(header) + 1;
> -	got_hash_init(&ctx, GOT_HASH_SHA1);
> +	got_hash_init(&ctx, pack->algo);
>  	got_hash_update(&ctx, header, headerlen);
>  	if (max_size > GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
>  		err = read_file_digest(&ctx, tmpfile, len);
> @@ -644,7 +644,7 @@ got_pack_index(struct got_pack *pack, int idxfd, FILE 
>  		    "bad packfile with zero objects");
>  
>  	/* We compute the SHA1 of pack file contents and verify later on. */
> -	got_hash_init(&ctx, GOT_HASH_SHA1);
> +	got_hash_init(&ctx, pack->algo);
>  	got_hash_update(&ctx, &hdr, sizeof(hdr));
>  
>  	/*
> blob - 1edd0153662b01a8fd962579a4b5a7c5af42df69
> file + lib/privsep.c
> --- lib/privsep.c
> +++ lib/privsep.c
> @@ -1960,6 +1960,7 @@ got_privsep_init_pack_child(struct imsgbuf *ibuf, stru
>  
>  	ipackidx.len = packidx->len;
>  	ipackidx.packfile_size = pack->filesize;
> +	ipackidx.algo = packidx->algo;
>  	fd = dup(packidx->fd);
>  	if (fd == -1)
>  		return got_error_from_errno("dup");
> blob - 7323331c86c9085cb6ec9fdad463a7ff32f92518
> file + lib/repository.c
> --- lib/repository.c
> +++ lib/repository.c
> @@ -1384,7 +1384,7 @@ got_repo_search_packidx(struct got_packidx **packidx, 
>  			continue; /* already searched */
>  
>  		err = got_packidx_open(packidx, got_repo_get_fd(repo),
> -		    path_packidx, 0);
> +		    path_packidx, 0, repo->algo);
>  		if (err)
>  			goto done;
>  
> @@ -1486,7 +1486,7 @@ got_repo_get_packidx(struct got_packidx **packidx, con
>  	/* No luck. Search the filesystem. */
>  
>  	err = got_packidx_open(packidx, got_repo_get_fd(repo),
> -	    path_packidx, 0);
> +	    path_packidx, 0, repo->algo);
>  	if (err)
>  		return err;
>  
> @@ -1817,7 +1817,7 @@ retry:
>  		path_packidx = pe->path;
>  
>  		err = got_packidx_open(&packidx, got_repo_get_fd(repo),
> -		    path_packidx, 0);
> +		    path_packidx, 0, repo->algo);
>  		if (err)
>  			break;
>  
> @@ -2563,7 +2563,7 @@ got_repo_get_packfile_info(int *npackfiles, int *nobje
>  		}
>  
>  		err = got_packidx_open(&packidx, got_repo_get_fd(repo),
> -		    path_packidx, 0);
> +		    path_packidx, 0, repo->algo);
>  		free(path_packidx);
>  		if (err)
>  			goto done;
> blob - b0168b3397ef9e155f6ca23c6057126006b3f1f6
> file + lib/repository_admin.c
> --- lib/repository_admin.c
> +++ lib/repository_admin.c
> @@ -548,7 +548,8 @@ got_repo_list_pack(FILE *packfile, struct got_object_i
>  		goto done;
>  	}
>  
> -	err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1);
> +	err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1,
> +	    repo->algo);
>  	if (err)
>  		goto done;
>  
> blob - aec894fa8b4604174f7faf23446d66e16ac0d570
> file + libexec/got-read-pack/got-read-pack.c
> --- libexec/got-read-pack/got-read-pack.c
> +++ libexec/got-read-pack/got-read-pack.c
> @@ -1146,6 +1146,7 @@ receive_packidx(struct got_packidx **packidx, struct i
>  	}
>  	memcpy(&ipackidx, imsg.data, sizeof(ipackidx));
>  
> +	p->algo = ipackidx.algo;
>  	p->fd = imsg_get_fd(&imsg);
>  	p->len = ipackidx.len;
>  	if (p->fd == -1) {
>