]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Move dirs reallocation from dirpool_make_dirtraverse to dirpool_add_dir
authorMichael Schroeder <mls@suse.de>
Mon, 18 May 2026 10:48:09 +0000 (12:48 +0200)
committerMichael Schroeder <mls@suse.de>
Mon, 18 May 2026 10:48:09 +0000 (12:48 +0200)
repo_add_solv does not use the correct DIR_BLOCK allocation, so we
need to extend the dirs array the first time we add a new directory.

We used to do this in dirpool_make_dirtraverse, but since commit
fa35e8672b478c410429d403b887277d7b17e57d the dirtraverse array is
no longer created when calling dirpool_add_dir. So we now do it
the first time the hash is created.

src/dirpool.c
src/repo_solv.c

index 6fc2c0b73838c25ae59770cd54b311d882ee59b6..45a391a18d2f7454d58b00f5e4d9480ceac28968 100644 (file)
@@ -82,9 +82,9 @@ void
 dirpool_make_dirtraverse(Dirpool *dp)
 {
   Id parent, i, *dirtraverse;
+  dp->dirtraverse = solv_free(dp->dirtraverse);
   if (!dp->ndirs)
     return;
-  dp->dirs = solv_extend_resize(dp->dirs, dp->ndirs, sizeof(Id), DIR_BLOCK);
   dirtraverse = solv_calloc_block(dp->ndirs, sizeof(Id), DIR_BLOCK);
   for (i = 0; i < dp->ndirs; i++)
     {
@@ -174,7 +174,12 @@ dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create)
 
   /* grow hash table if load factor exceeds 50% */
   if ((Hashval)dp->ndirs * 2 >= dp->dirhashmask)
-    dirpool_resize_hash(dp, DIR_BLOCK);
+    {
+      /* hack: repo_add_solv will not use DIR_BLOCK, so realloc here */
+      if (!dp->dirhashmask)
+        dp->dirs = solv_extend_resize(dp->dirs, dp->ndirs, sizeof(Id), DIR_BLOCK);
+      dirpool_resize_hash(dp, DIR_BLOCK);
+    }
 
   ht = dp->dirhashtbl;
   hm = dp->dirhashmask;
index b18270628e915269e93f3edcff7f3b7bcda32af4..4ddee644c334d8cc5605dee6d6ad31dcbb46a0fd 100644 (file)
@@ -873,6 +873,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
   /*******  Part 3: Dirs  ***********************************************/
   if (numdir)
     {
+      /* note that we do not use DIR_BLOCK here. See comment in dirpool_add_dir */
       data.dirpool.dirs = solv_malloc2(numdir, sizeof(Id));
       data.dirpool.ndirs = numdir;
       data.dirpool.dirs[0] = 0;                /* dir 0: virtual root */