aboutsummaryrefslogtreecommitdiffstats
path: root/core/apk-tools/delay-state-init.patch
blob: 397d2d4c233422972b44e86c08f72881308e1795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
commit 110611c53c8e1b09c27c8c516c7f7c0baf47f68b
Author: Natanael Copa <ncopa@alpinelinux.org>
Date:   Mon May 11 12:02:00 2009 +0000

    add: delay state initialization til we have all pkgs in db
    
    The state size is taken from name_id and cannot be extended. So we
    must wait with initializing the state til we have all packages added
    to the db.
    
    We must also always allocate the package name, incase its not in the
    repository. This is done with apk_db_get_name().

diff --git a/src/add.c b/src/add.c
index 77abc3b..9efab15 100644
--- a/src/add.c
+++ b/src/add.c
@@ -41,13 +41,13 @@ static int add_main(void *ctx, int argc, char **argv)
 	struct add_ctx *actx = (struct add_ctx *) ctx;
 	struct apk_database db;
 	struct apk_state *state;
+	struct apk_dependency_array *pkgs; /* list of pkgs to install */
 	int i, r;
 
 	r = apk_db_open(&db, apk_root, actx->open_flags | APK_OPENF_WRITE);
 	if (r != 0)
 		return r;
 
-	state = apk_state_new(&db);
 	for (i = 0; i < argc; i++) {
 		struct apk_dependency dep;
 
@@ -61,7 +61,7 @@ static int add_main(void *ctx, int argc, char **argv)
 			}
 
 			dep = (struct apk_dependency) {
-				.name = pkg->name,
+				.name = apk_db_get_name(&db, APK_BLOB_STR(pkg->name->name)),
 				.version = pkg->version,
 				.result_mask = APK_VERSION_EQUAL,
 			};
@@ -71,14 +71,18 @@ static int add_main(void *ctx, int argc, char **argv)
 				.result_mask = APK_DEPMASK_REQUIRE,
 			};
 		}
-		apk_deps_add(&db.world, &dep);
 		dep.name->flags |= APK_NAME_TOPLEVEL;
+		apk_deps_add(&pkgs, &dep);
+	}
 
-		r = apk_state_lock_dependency(state, &dep);
+	state = apk_state_new(&db);
+	for (i = 0; i < pkgs->num; i++) {
+		r = apk_state_lock_dependency(state, &pkgs->item[i]);
 		if (r != 0) {
-			apk_error("Unable to install '%s'", dep.name->name);
+			apk_error("Unable to install '%s'", pkgs->item[i].name->name);
 			goto err;
 		}
+		apk_deps_add(&db.world, &pkgs->item[i]);
 	}
 	r = apk_state_commit(state, &db);
 err: