Преглед изворни кода

libdpkg: Refactor trig_awaited_pend_head processing into new functions

This will allow accessing trig_awaited_pend_head from a different
module, w/o needing to pull in triglib.
Guillem Jover пре 15 година
родитељ
комит
a4298e6ff2
2 измењених фајлова са 25 додато и 8 уклоњено
  1. 20 8
      lib/dpkg/triglib.c
  2. 5 0
      lib/dpkg/triglib.h

+ 20 - 8
lib/dpkg/triglib.c

@@ -4,6 +4,7 @@
  *
  * Copyright © 2007 Canonical Ltd
  * Written by Ian Jackson <ian@chiark.greenend.org.uk>
+ * Copyright © 2008-2011 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -203,6 +204,23 @@ trig_awaited_pend_enqueue(struct pkginfo *pend)
 	pkg_list_prepend(&trig_awaited_pend_head, pend);
 }
 
+void
+trig_awaited_pend_foreach(trig_awaited_pend_foreach_func *func)
+{
+	struct pkg_list *tp;
+
+	for (tp = trig_awaited_pend_head; tp; tp = tp->next)
+		if (!tp->pkg->trigpend_head)
+			func(tp->pkg);
+}
+
+void
+trig_awaited_pend_free(void)
+{
+	pkg_list_free(trig_awaited_pend_head);
+	trig_awaited_pend_head = NULL;
+}
+
 /*
  * Fix up packages in state triggers-awaited w/o the corresponding package
  * with pending triggers. This can happen when dpkg was interrupted
@@ -215,17 +233,11 @@ trig_awaited_pend_enqueue(struct pkginfo *pend)
 void
 trig_fixup_awaiters(enum modstatdb_rw cstatus)
 {
-	struct pkg_list *tp;
-
 	if (cstatus < msdbrw_write)
 		return;
 
-	for (tp = trig_awaited_pend_head; tp; tp = tp->next)
-		if (!tp->pkg->trigpend_head)
-			trig_clear_awaiters(tp->pkg);
-
-	pkg_list_free(trig_awaited_pend_head);
-	trig_awaited_pend_head = NULL;
+	trig_awaited_pend_foreach(trig_clear_awaiters);
+	trig_awaited_pend_free();
 }
 
 /*---------- Generalized handling of trigger kinds. ----------*/

+ 5 - 0
lib/dpkg/triglib.h

@@ -83,7 +83,12 @@ bool trig_note_pend(struct pkginfo *pend, const char *trig /*not copied!*/);
 bool trig_note_aw(struct pkginfo *pend, struct pkginfo *aw);
 void trig_clear_awaiters(struct pkginfo *notpend);
 
+typedef void trig_awaited_pend_foreach_func(struct pkginfo *pkg);
+
 void trig_awaited_pend_enqueue(struct pkginfo *pend);
+void trig_awaited_pend_foreach(trig_awaited_pend_foreach_func *func);
+void trig_awaited_pend_free(void);
+
 void trig_fixup_awaiters(enum modstatdb_rw cstatus);
 
 void trig_file_interests_ensure(void);