Codebase list cdebconf / 9720e07
* Add a remove method to the question database; use this to migrate questions to the correct stacked database in the event that their types change (fixes preseeded passwords ending up in questions.dat on the installed system in some cases). r35410 Colin Watson 18 years ago
7 changed file(s) with 79 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
2323 * Reset question template pointers whenever they change, not just when the
2424 tag changes; do this in X_LOADTEMPLATEFILE and dpkg-reconfigure as well
2525 as debconf-loadtemplate.
26 * Add a remove method to the question database; use this to migrate
27 questions to the correct stacked database in the event that their types
28 change (fixes preseeded passwords ending up in questions.dat on the
29 installed system in some cases).
2630
2731 -- Attilio Fiandrotti <fiandro@tiscali.it> Wed, 8 Mar 2006 22:40:40 +0100
2832
146146 dcd_question_set_t question_set;
147147 dcd_question_disown_t question_disown;
148148 dcd_question_disownall_t question_disownall;
149 dcd_question_remove_t question_remove;
149150 dcd_question_lock_t question_lock;
150151 dcd_question_unlock_t question_unlock;
151152 dcd_question_visible_t question_visible;
203204 name is "name".
204205 XXX should return NULL if fails?
205206
206 int *template_remove(struct database *, char *name):
207 int template_remove(struct database *, char *name):
207208 remove a template from the database
208209
209 int *(template|question)_[un]lock(struct database *, char *name):
210 int (template|question)_[un]lock(struct database *, char *name):
210211 XXX WTF? Nothing implements this right now
211212
212213 struct template *template_iterate(struct database *, void **iter):
244245 Semantically, this should be the same as iterating, and for each question
245246 removing the owner and resetting it. However, you might be able to avoid
246247 iterating on some of the question, if the backend is structured correctly.
248
249 int question_remove(struct database *, char *name):
250 remove a question from the database (useful while moving a question to a
251 different database)
247252
248253 int question_visible(struct database *, char *name, char *priority)
249254 XXX - WTF, nothing implements this either.
254254 question_deref(q);
255255 }
256256 return 0;
257 }
258
259 static int question_db_remove(struct question_db *db, const char *name)
260 {
261 return DC_NOTIMPL;
257262 }
258263
259264 static int question_db_lock(struct question_db *db, const char *name)
422427 SETMETHOD(get);
423428 SETMETHOD(disown);
424429 SETMETHOD(disownall);
430 SETMETHOD(remove);
425431 SETMETHOD(lock);
426432 SETMETHOD(unlock);
427433 SETMETHOD(is_visible);
4343 struct question *(*get)(struct question_db *db, const char *name);
4444 int (*disown)(struct question_db *, const char *name, const char *owner);
4545 int (*disownall)(struct question_db *, const char *owner);
46 int (*remove)(struct question_db *, const char *name);
4647 int (*lock)(struct question_db *, const char *name);
4748 int (*unlock)(struct question_db *, const char *name);
4849 int (*is_visible)(struct question_db *, const char *name, const char *priority);
300300 return DC_OK;
301301 }
302302
303 /* FIXME b0rken */
304303 static int rfc822db_template_remove(struct template_db *db, const char *tag)
305304 {
306305 struct template_db_cache *dbdata = db->data;
308307
309308 INFO(INFO_VERBOSE, "rfc822db_template_remove(db,tag=%s)",tag);
310309
310 memset(&t2, 0, sizeof (struct template));
311311 t2.tag = (char*) tag;
312 t = tdelete(&t, &dbdata->root, nodetemplatecomp);
312 t = tfind(&t2, &dbdata->root, nodetemplatecomp);
313313
314314 if (t)
315315 {
316 t = *(struct template **) t;
317 tdelete(t, &dbdata->root, nodetemplatecomp);
316318 template_deref(t);
317319 return DC_OK;
318320 }
602604 return DC_OK;
603605 }
604606
607 static int rfc822db_question_remove(struct question_db *db, const char *tag)
608 {
609 struct question_db_cache *dbdata = db->data;
610 struct question *q, q2;
611
612 INFO(INFO_VERBOSE, "rfc822db_question_remove(db,tag=%s)", tag);
613
614 memset(&q2, 0, sizeof (struct question));
615 q2.tag = (char*) tag;
616 q = tfind(&q2, &dbdata->root, nodequestioncomp);
617 if (q != NULL) {
618 q = *(struct question **) q;
619 tdelete(q, &dbdata->root, nodequestioncomp);
620 question_deref(q);
621 return DC_OK;
622 }
623 return DC_NOTOK;
624 }
625
605626 /* TODO: This is an ugly hack because there's no better way to do this
606627 * within the constraints of twalk() (since there's no user-data argument).
607628 * If we ever switch to some other tree API, this should go away
672693 set: rfc822db_question_set,
673694 get: rfc822db_question_get,
674695 disown: rfc822db_question_disown,
696 remove: rfc822db_question_remove,
675697 iterate: rfc822db_question_iterate,
676698 };
677699
128128 while (tstack) {
129129 ret = tstack->db->methods.accept(tstack->db, t->tag, t->type);
130130 if (ret == DC_REJECT) {
131 tstack->db->methods.remove(tstack->db, t->tag);
131132 tstack = tstack->next;
132133 continue;
133134 }
138139 case DC_NOTOK:
139140 return DC_NOTOK;
140141 case DC_REJECT: /* obsolete as return code from set() */
142 tstack->db->methods.remove(tstack->db, t->tag);
141143 tstack = tstack->next;
142144 continue;
143145 }
288290 const char *type = t->template ? t->template->type : "";
289291 ret = qstack->db->methods.accept(qstack->db, t->tag, type);
290292 if (ret == DC_REJECT) {
293 qstack->db->methods.remove(qstack->db, t->tag);
291294 qstack = qstack->next;
292295 continue;
293296 }
298301 case DC_NOTOK:
299302 return DC_NOTOK;
300303 case DC_REJECT: /* obsolete as return code from set() */
304 qstack->db->methods.remove(qstack->db, t->tag);
301305 qstack = qstack->next;
302306 continue;
303307 }
349353 qstack = qstack->next;
350354 }
351355 return DC_OK;
356 }
357
358 static int stack_question_db_remove(struct question_db *db, const char *name)
359 {
360 struct question_stack *qstack = (struct question_stack *)db->data;
361 struct question *q;
362 while (qstack) {
363 q = qstack->db->methods.get(qstack->db, name);
364 if (q) {
365 question_deref(q);
366 return qstack->db->methods.remove(qstack->db, name);
367 }
368 qstack = qstack->next;
369 }
370 /* nobody had it? fail. */
371 return DC_NOTOK;
352372 }
353373
354374 static int stack_question_db_lock(struct question_db *db, const char *name)
409429 get: stack_question_db_get,
410430 disown: stack_question_db_disown,
411431 disownall: stack_question_db_disownall,
432 remove: stack_question_db_remove,
412433 iterate: stack_question_db_iterate,
413434 lock: stack_question_db_lock,
414435 unlock: stack_question_db_unlock,
380380 return DC_OK;
381381 }
382382
383 static int textdb_question_remove(struct question_db *db, const char *tag)
384 {
385 char *filename;
386
387 if (tag == NULL) return DC_NOTOK;
388
389 /* questions are not cached at present */
390
391 filename = question_filename(db, tag);
392 if (unlink(filename) == 0)
393 return DC_OK;
394 else
395 return DC_NOTOK;
396 }
397
383398 static struct question *textdb_question_iterate(struct question_db *db,
384399 void **iter)
385400 {
435450 set: textdb_question_set,
436451 get: textdb_question_get,
437452 disown: textdb_question_disown,
453 remove: textdb_question_remove,
438454 iterate: textdb_question_iterate,
439455 };
440456