Explorar o código

Make modstatdb available file options explicit

The options were either explicit or dependent on the main status
options, now they are always explicit. This detangles the actions
on the available file from the ones on the status file. Rename the
enum flags accordingly.
Guillem Jover %!s(int64=15) %!d(string=hai) anos
pai
achega
6761f32a6b
Modificáronse 5 ficheiros con 16 adicións e 14 borrados
  1. 7 5
      lib/dpkg/dbmodify.c
  2. 3 3
      lib/dpkg/dpkg-db.h
  3. 2 2
      src/archives.c
  4. 1 1
      src/enquiry.c
  5. 3 3
      src/querycmd.c

+ 7 - 5
lib/dpkg/dbmodify.c

@@ -209,8 +209,8 @@ modstatdb_init(const char *admindir, enum modstatdb_rw readwritereq)
     m_asprintf(fnip->store, "%s/%s", admindir, fnip->suffix);
   }
 
-  cflags= readwritereq & msdbrw_flagsmask;
-  readwritereq &= ~msdbrw_flagsmask;
+  cflags = readwritereq & msdbrw_available_mask;
+  readwritereq &= ~msdbrw_available_mask;
 
   switch (readwritereq) {
   case msdbrw_needsuperuser:
@@ -244,7 +244,7 @@ modstatdb_init(const char *admindir, enum modstatdb_rw readwritereq)
 
   if (cstatus != msdbrw_needsuperuserlockonly) {
     cleanupdates();
-    if (cflags & msdbrw_available)
+    if (cflags >= msdbrw_available_readonly)
     parsedb(availablefile,
             pdb_recordavailable | pdb_rejectstatus | pdb_lax_parser,
             NULL);
@@ -282,11 +282,13 @@ void modstatdb_checkpoint(void) {
 
 void modstatdb_shutdown(void) {
   const struct fni *fnip;
+
+  if (cflags >= msdbrw_available_write)
+    writedb(availablefile, 1, 0);
+
   switch (cstatus) {
   case msdbrw_write:
     modstatdb_checkpoint();
-    if (cflags & msdbrw_available && !(cflags & msdbrw_available_readonly))
-      writedb(availablefile, 1, 0);
     /* Tidy up a bit, but don't worry too much about failure. */
     fclose(importanttmp);
     unlink(importanttmpfile);

+ 3 - 3
lib/dpkg/dpkg-db.h

@@ -216,10 +216,10 @@ enum modstatdb_rw {
   msdbrw_write/*s*/, msdbrw_needsuperuser,
 
   /* Now some optional flags: */
-  msdbrw_flagsmask= ~077,
+  msdbrw_available_mask= ~077,
   /* Flags start at 0100. */
-  msdbrw_available = 0100,
-  msdbrw_available_readonly = 0200,
+  msdbrw_available_readonly = 0100,
+  msdbrw_available_write = 0200,
 };
 
 bool modstatdb_is_locked(const char *admindir);

+ 2 - 2
src/archives.c

@@ -1183,10 +1183,10 @@ void archivefiles(const char *const *argv) {
 
   modstatdb_init(admindir,
                  f_noact ?                          msdbrw_readonly :
-                 (cipaction->arg_int == act_avail ? msdbrw_write :
+                 (cipaction->arg_int == act_avail ? msdbrw_readonly :
                   fc_nonroot ?                      msdbrw_write :
                                                     msdbrw_needsuperuser) |
-                 msdbrw_available);
+                 msdbrw_available_write);
 
   checkpath();
   log_message("startup archives %s", cipaction->olong);

+ 1 - 1
src/enquiry.c

@@ -348,7 +348,7 @@ void predeppackage(const char *const *argv) {
   if (*argv)
     badusage(_("--%s takes no arguments"), cipaction->olong);
 
-  modstatdb_init(admindir, msdbrw_readonly | msdbrw_available);
+  modstatdb_init(admindir, msdbrw_readonly | msdbrw_available_readonly);
   /* We use clientdata->istobe to detect loops. */
   clear_istobes();
 

+ 3 - 3
src/querycmd.c

@@ -204,7 +204,7 @@ listpackages(const char *const *argv)
   if (!*argv)
     modstatdb_init(admindir, msdbrw_readonly);
   else
-    modstatdb_init(admindir, msdbrw_readonly | msdbrw_available);
+    modstatdb_init(admindir, msdbrw_readonly | msdbrw_available_readonly);
 
   pkg_array_init_from_db(&array);
   pkg_array_sort(&array, pkg_sorter_by_name);
@@ -372,7 +372,7 @@ enqperpackage(const char *const *argv)
     badusage(_("--%s needs at least one package name argument"), cipaction->olong);
 
   if (cipaction->arg_int == act_printavail)
-    modstatdb_init(admindir, msdbrw_readonly | msdbrw_available);
+    modstatdb_init(admindir, msdbrw_readonly | msdbrw_available_readonly);
   else
     modstatdb_init(admindir, msdbrw_readonly);
 
@@ -472,7 +472,7 @@ showpackages(const char *const *argv)
   if (!*argv)
     modstatdb_init(admindir, msdbrw_readonly);
   else
-    modstatdb_init(admindir, msdbrw_readonly | msdbrw_available);
+    modstatdb_init(admindir, msdbrw_readonly | msdbrw_available_readonly);
 
   pkg_array_init_from_db(&array);
   pkg_array_sort(&array, pkg_sorter_by_name);