summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/opkg/opkg/0006-detect-circular-dependencies.patch
blob: 5cf8618170e46f24a74dfaf21f6c7b63d7b9e1c3 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From f434078a342435ae8a666b599d989c30d4c6a7f5 Mon Sep 17 00:00:00 2001
From: Richard Purdie <richard.purdie@linuxfoundation.org>
Date: Sun, 18 Dec 2011 23:54:30 +0000
Subject: [PATCH 6/7] detect circular dependencies

Add logic to detect circular dependencies. If we see any dependency from
any given parent twice, ignore it the second time and print a notice message
that we did so.

Upstream-Status: Submitted
http://code.google.com/p/opkg/issues/detail?id=93

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 libopkg/opkg_install.c | 8 ++++++++
 libopkg/pkg.c          | 2 ++
 libopkg/pkg.h          | 1 +
 libopkg/pkg_depends.c  | 3 +--
 libopkg/pkg_depends.h  | 1 +
 5 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c
index 1632066..0216914 100644
--- a/libopkg/opkg_install.c
+++ b/libopkg/opkg_install.c
@@ -84,8 +84,14 @@ satisfy_dependencies_for(pkg_t *pkg)
 	       /* The package was uninstalled when we started, but another
 	          dep earlier in this loop may have depended on it and pulled
 	          it in, so check first. */
+               if (is_pkg_in_pkg_vec(dep->wanted_by, pkg)) {
+		    opkg_msg(NOTICE,"Breaking cicular dependency on %s for %s.\n", pkg->name, dep->name);
+	            continue;
+               }
 	       if ((dep->state_status != SS_INSTALLED) && (dep->state_status != SS_UNPACKED)) {
 		    opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n");
+                    if (!is_pkg_in_pkg_vec(dep->wanted_by, pkg))
+     	                 pkg_vec_insert(dep->wanted_by, pkg);
 		    err = opkg_install_pkg(dep, 0);
 		    /* mark this package as having been automatically installed to
 		     * satisfy a dependency */
@@ -115,6 +121,8 @@ satisfy_dependencies_for(pkg_t *pkg)
 	  /* The package was uninstalled when we started, but another
 	     dep earlier in this loop may have depended on it and pulled
 	     it in, so check first. */
+          if (!is_pkg_in_pkg_vec(dep->wanted_by, pkg))
+	       pkg_vec_insert(dep->wanted_by, pkg);
 	  if ((dep->state_status != SS_INSTALLED)
 	      && (dep->state_status != SS_UNPACKED)) {
                opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n");
diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index 6ccbde2..be486ee 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -86,6 +86,7 @@ pkg_init(pkg_t *pkg)
      pkg->section = NULL;
      pkg->description = NULL;
      pkg->state_want = SW_UNKNOWN;
+     pkg->wanted_by = pkg_vec_alloc();
      pkg->state_flag = SF_OK;
      pkg->state_status = SS_NOT_INSTALLED;
      pkg->depends_str = NULL;
@@ -191,6 +192,7 @@ pkg_deinit(pkg_t *pkg)
 	pkg->description = NULL;
 
 	pkg->state_want = SW_UNKNOWN;
+	pkg_vec_free(pkg->wanted_by);
 	pkg->state_flag = SF_OK;
 	pkg->state_status = SS_NOT_INSTALLED;
 
diff --git a/libopkg/pkg.h b/libopkg/pkg.h
index 775b656..5d468cb 100644
--- a/libopkg/pkg.h
+++ b/libopkg/pkg.h
@@ -129,6 +129,7 @@ struct pkg
      char *description;
      char *tags;
      pkg_state_want_t state_want;
+     pkg_vec_t *wanted_by;
      pkg_state_flag_t state_flag;
      pkg_state_status_t state_status;
      char **depends_str;
diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c
index 36c76aa..a72eed7 100644
--- a/libopkg/pkg_depends.c
+++ b/libopkg/pkg_depends.c
@@ -30,7 +30,6 @@ static int parseDepends(compound_depend_t *compound_depend, char * depend_str);
 static depend_t * depend_init(void);
 static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
 static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
-static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
 
 static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
 {
@@ -531,7 +530,7 @@ int pkg_dependence_satisfied(depend_t *depend)
      return 0;
 }
 
-static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
+int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
 {
     int i;
     pkg_t ** pkgs = vec->pkgs;
diff --git a/libopkg/pkg_depends.h b/libopkg/pkg_depends.h
index b8072e2..ca0801f 100644
--- a/libopkg/pkg_depends.h
+++ b/libopkg/pkg_depends.h
@@ -87,5 +87,6 @@ pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
 int pkg_dependence_satisfiable(depend_t *depend);
 int pkg_dependence_satisfied(depend_t *depend);
 const char* constraint_to_str(enum version_constraint c);
+int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
 
 #endif
-- 
1.7.12