[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] added --force-* options for conffile handling



This patch attempts to resolve some issues referenced in bug #4950 and lots
of others. Basically it adds four new --force-* options detailed below. This
is the last step to non-interactive upgrades.

What we have now is a situation where if there are changes from the old and
new conffile, dpkg prompts for what to do about it. Given that dpkg usually
has a sane default, and the admin usually has a good idea of what he/she
wants to do with these requests, we can supply options to get the desired
affect. Also with the current dpkg, if you remove a conffile completely,
there is no simple task for resinstalling it, since dpkg will not replace
missing conffiles with new ones.

The options added are:

  --force-confnew:	Obviously this forces dpkg to _always_ install the new
			config file without prompting.

  --force-confold:	Again, this _always_ uses the old config file without
			prompting.

  --force-confdef:	This tells dpkg to use the default choice when replacing
			config files if there is a sane default. Note, there are
			cases where dpkg concludes no default is possible, so a
			prompt would still be given in those (remote) cases.

  --force-confmiss:	This tells dpkg to actually install the new config file
			if the old one is missing.

Now the interesting part. You notice in the "confdef" force mode that there is
still a chance of a prompt. If you mix --force-confdef and --force-conf{old,new},
then you will get the default choice. If there is no default then dpkg will use
the --force-conf{old,new} option to decide what to do.

Hopefully this can make for sane auto-upgrades.

Ben
diff -urN dpkg-1.4.1.13.old/main/configure.c dpkg-1.4.1.13/main/configure.c
--- dpkg-1.4.1.13.old/main/configure.c	Sun Nov  1 11:06:21 1998
+++ dpkg-1.4.1.13/main/configure.c	Mon Oct 11 11:06:04 1999
@@ -185,6 +185,12 @@
         useredited= -1;
         distedited= -1;
         what= cfo_identical;
+      } else if (!strcmp(currenthash,NONEXISTENTFLAG) && fc_conff_miss) {
+	fprintf(stderr, _("\nConfiguration file `%s', does not exist on system.\n"
+	    "Installing new config file as you request.\n"), conff->name);
+	what= cfo_newconff;
+	useredited= -1;
+	distedited= -1;
       } else if (!strcmp(conff->hash,NEWCONFFILEFLAG)) {
         if (!strcmp(currenthash,NONEXISTENTFLAG)) {
           what= cfo_newconff;
@@ -205,6 +211,16 @@
             "deferred_configure `%s' (= `%s') useredited=%d distedited=%d what=%o",
             conff->name, cdr.buf, useredited, distedited, what);
       
+      /* When prompting we check for some of the force options. There are
+       * several cases in which these occur.
+       *  - We have --force-confnew, in which we always use the new config file
+       *  - We have --force-confold, in which we always use the old config file
+       *  - We have --force-confdef, in which we always use the default action
+       *    if there is one. Note, there are cases where we will still prompt
+       *  - If we have --force-confdef and one of the others (new/old) then we
+       *    always use the default where we can. If there is no default, then we
+       *    use the new or old, depending on which --force-conf{old,new} was used.
+       */
       if (what & cfof_prompt) {
 
         do {
@@ -232,6 +248,28 @@
 
           }
           
+	  if (!(fc_conff_def && (what & (cfof_install|cfof_keep)))) {
+	    if (fc_conff_new) {
+	      fprintf(stderr, _(" ==> Using new file as you requested.\n"));
+	      cc = 'y';
+	      break;
+	    } else if (fc_conff_old) {
+	      fprintf(stderr, _(" ==> Using current old file as you requested.\n"));
+	      cc = 'n';
+	      break;
+	    }
+	  }
+
+          if (what & cfof_keep && fc_conff_def) {
+            fprintf(stderr, _(" ==> Keeping old config file as default.\n"));
+	    cc = 'n';
+	    break;
+	  } else if (what & cfof_install && fc_conff_def) {
+	    fprintf(stderr, _(" ==> Using new config file as default.\n"));
+	    cc = 'y';
+	    break;
+	  }
+
           fprintf(stderr,
                   _("   What would you like to do about it ?  Your options are:\n"
                   "    Y or I  : install the package maintainer's version\n"
diff -urN dpkg-1.4.1.13.old/main/main.c dpkg-1.4.1.13/main/main.c
--- dpkg-1.4.1.13.old/main/main.c	Thu Sep  9 19:48:24 1999
+++ dpkg-1.4.1.13/main/main.c	Mon Oct 11 10:22:11 1999
@@ -132,7 +132,8 @@
 int fc_downgrade=1, fc_configureany=0, fc_hold=0, fc_removereinstreq=0, fc_overwrite=0;
 int fc_removeessential=0, fc_conflicts=0, fc_depends=0, fc_dependsversion=0;
 int fc_autoselect=1, fc_badpath=0, fc_overwritediverted=0, fc_architecture=0;
-int fc_nonroot=0, fc_overwritedir=0;
+int fc_nonroot=0, fc_overwritedir=0, fc_conff_new=0, fc_conff_miss=0;
+int fc_conff_old=0, fc_conff_def=0;
 
 int errabort = 50;
 const char *admindir= ADMINDIR;
@@ -149,6 +150,10 @@
   { "remove-reinstreq",    &fc_removereinstreq          },
   { "remove-essential",    &fc_removeessential          },
   { "conflicts",           &fc_conflicts                },
+  { "confnew",             &fc_conff_new                },
+  { "confold",             &fc_conff_old                },
+  { "confdef",             &fc_conff_def                },
+  { "confmiss",            &fc_conff_miss               },
   { "depends",             &fc_depends                  },
   { "depends-version",     &fc_dependsversion           },
   { "auto-select",         &fc_autoselect               },
@@ -268,6 +273,13 @@
   overwrite-diverted     Overwrite a diverted file with an undiverted version\n\
   depends-version [!]    Turn dependency version problems into warnings\n\
   depends [!]            Turn all dependency problems into warnings\n\
+  confnew [!]            Always use the new config files, don't prompt\n\
+  confold [!]            Always use the old config files, don't prompt\n\
+  confdef [!]            Use the default option for new config files if one\n\
+                         is available, don't prompt. If no default can be found,\n\
+                         you will be prompted unless one of the confold or\n\
+                         confnew options is also given\n\
+  confmiss [!]           Always install missing config files\n\
   conflicts [!]          Allow installation of conflicting packages\n\
   architecture [!]       Process even packages with wrong architecture\n\
   overwrite-dir [!]      Overwrite one package's directory with another's file\n\
diff -urN dpkg-1.4.1.13.old/main/main.h dpkg-1.4.1.13/main/main.h
--- dpkg-1.4.1.13.old/main/main.h	Thu Sep  9 19:53:04 1999
+++ dpkg-1.4.1.13/main/main.h	Mon Oct 11 10:51:24 1999
@@ -83,7 +83,8 @@
 extern int fc_downgrade, fc_configureany, fc_hold, fc_removereinstreq, fc_overwrite;
 extern int fc_removeessential, fc_conflicts, fc_depends, fc_dependsversion;
 extern int fc_autoselect, fc_badpath, fc_overwritediverted, fc_architecture;
-extern int fc_nonroot, fc_overwritedir;
+extern int fc_nonroot, fc_overwritedir, fc_conff_new, fc_conff_miss;
+extern int fc_conff_old, fc_conff_def;
 
 extern int errabort;
 extern const char *admindir;
@@ -165,6 +166,8 @@
 
 int ignore_depends(struct pkginfo *pkg);
 int force_depends(struct deppossi *possi);
+int force_conff_new(struct deppossi *possi);
+int force_conff_miss(struct deppossi *possi);
 int force_conflicts(struct deppossi *possi);
 void ensure_package_clientdata(struct pkginfo *pkg);
 const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile);

Attachment: pgpyh0FmTlhO_.pgp
Description: PGP signature


Reply to: