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

From:
Omar Polo <op@omarpolo.com>
Subject:
adjust GOT_PACKIDX_NAMELEN for sha256 packs
To:
gameoftrees@openbsd.org
Date:
Thu, 11 Jul 2024 14:54:07 +0200

Download raw body.

Thread
This needs the got_hash_digest{,_string}_length() I'm adding in my
previous mail.

The alternative would be to change it to be more like
GOT_PACKIDX_NAMELEN that's just a minimum length and not an exact
requirement.

-----------------------------------------------
commit 13914379400f1dc4b4f6ce93250c628014fefa7c
from: Omar Polo <op@omarpolo.com>
date: Thu Jul 11 12:13:49 2024 UTC
 
 adjest GOT_PACKIDX_NAMELEN for sha256 packs
 
diff 39ed7bd6df2cf61cb90dc543a311aa09ecb9a74f 13914379400f1dc4b4f6ce93250c628014fefa7c
commit - 39ed7bd6df2cf61cb90dc543a311aa09ecb9a74f
commit + 13914379400f1dc4b4f6ce93250c628014fefa7c
blob - e813447f99bea12da2a2e63fe9373bd05dd76ea0
blob + 3e92ba6691fe0dd45e35da5d41424073f43329f6
--- lib/got_lib_pack.h
+++ lib/got_lib_pack.h
@@ -56,9 +56,9 @@ const struct got_error *got_pack_parse_object_type_and
 #define GOT_PACKFILE_NAMELEN	(strlen(GOT_PACK_PREFIX) + \
 				SHA1_DIGEST_STRING_LENGTH - 1 + \
 				strlen(GOT_PACKFILE_SUFFIX))
-#define GOT_PACKIDX_NAMELEN	(strlen(GOT_PACK_PREFIX) + \
-				SHA1_DIGEST_STRING_LENGTH - 1 + \
-				strlen(GOT_PACKIDX_SUFFIX))
+#define GOT_PACKIDX_NAMELEN(digest_len) \
+				(strlen(GOT_PACK_PREFIX) + \
+				digest_len - 1 + strlen(GOT_PACKIDX_SUFFIX))
 
 /* See Documentation/technical/pack-format.txt in Git. */
 
blob - 606d32e822167999828d4333a09b3b6ee296bf61
blob + 825c284a4e4d1d2d2a5c1a4d62d6ba968820390a
--- lib/got_lib_repository.h
+++ lib/got_lib_repository.h
@@ -159,7 +159,7 @@ const struct got_error*got_repo_cache_raw_object(struc
     struct got_object_id *, struct got_raw_object *);
 struct got_raw_object *got_repo_get_cached_raw_object(struct got_repository *,
     struct got_object_id *);
-int got_repo_is_packidx_filename(const char *, size_t);
+int got_repo_is_packidx_filename(const char *, size_t, enum got_hash_algorithm);
 int got_repo_check_packidx_bloom_filter(struct got_repository *,
     const char *, struct got_object_id *);
 const struct got_error *got_repo_search_packidx(struct got_packidx **, int *,
blob - 0d7fadbd1906889c21ed98e3cd2febdfb48d6aff
blob + b9b9867c0d6fd8d638bb3e05a0cf78e3e5b22db3
--- lib/repository.c
+++ lib/repository.c
@@ -1182,16 +1182,21 @@ cache_packidx(struct got_repository *repo, struct got_
 }
 
 int
-got_repo_is_packidx_filename(const char *name, size_t len)
+got_repo_is_packidx_filename(const char *name, size_t len,
+    enum got_hash_algorithm algo)
 {
-	if (len != GOT_PACKIDX_NAMELEN)
+	size_t idlen;
+
+	idlen = got_hash_digest_string_length(algo);
+
+	if (len != GOT_PACKIDX_NAMELEN(idlen))
 		return 0;
 
 	if (strncmp(name, GOT_PACK_PREFIX, strlen(GOT_PACK_PREFIX)) != 0)
 		return 0;
 
-	if (strcmp(name + strlen(GOT_PACK_PREFIX) +
-	    SHA1_DIGEST_STRING_LENGTH - 1, GOT_PACKIDX_SUFFIX) != 0)
+	if (strcmp(name + strlen(GOT_PACK_PREFIX) + idlen - 1,
+	    GOT_PACKIDX_SUFFIX) != 0)
 		return 0;
 
 	return 1;
@@ -1444,7 +1449,8 @@ got_repo_list_packidx(struct got_pathlist_head *packid
 	repo->pack_path_mtime.tv_nsec = sb.st_mtim.tv_nsec;
 
 	while ((dent = readdir(packdir)) != NULL) {
-		if (!got_repo_is_packidx_filename(dent->d_name, dent->d_namlen))
+		if (!got_repo_is_packidx_filename(dent->d_name, dent->d_namlen,
+		    repo->algo))
 			continue;
 
 		if (asprintf(&path_packidx, "%s/%s", GOT_OBJECTS_PACK_DIR,
@@ -2554,7 +2560,8 @@ got_repo_get_packfile_info(int *npackfiles, int *nobje
 	}
 
 	while ((dent = readdir(packdir)) != NULL) {
-		if (!got_repo_is_packidx_filename(dent->d_name, dent->d_namlen))
+		if (!got_repo_is_packidx_filename(dent->d_name, dent->d_namlen,
+		    repo->algo))
 			continue;
 
 		if (asprintf(&path_packidx, "%s/%s", GOT_OBJECTS_PACK_DIR,
blob - a5cc628fec534d7d4aad89002bea4e0202645c0c
blob + 03c1217ed0277b948ed87ecc9f43da09009b24e2
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -1540,7 +1540,8 @@ got_repo_remove_lonely_packidx(struct got_repository *
 				goto done;
 		}
 
-		if (!got_repo_is_packidx_filename(dent->d_name, dent->d_namlen))
+		if (!got_repo_is_packidx_filename(dent->d_name, dent->d_namlen,
+		    got_repo_get_object_format(repo)))
 			continue;
 
 		err = got_packidx_get_packfile_path(&pack_relpath,