The following commit has been merged in the master branch: commit f65316a5ec488a52cb7d5fa98824c21629de26b6 Author: Guillem Jover <guil...@debian.org> Date: Sun May 15 03:39:35 2011 +0200
libdpkg: Use new writedb flags instead of independent bool variables Using bool to pass flags to a function already taking several arguments is generally a bad interface, as it's not clear from the call sites what each of them refer to. Switch to a proper enum with named flags instead. diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c index dc97dc4..4df78f6 100644 --- a/lib/dpkg/dbmodify.c +++ b/lib/dpkg/dbmodify.c @@ -95,7 +95,7 @@ static void cleanupdates(void) { } if (cstatus >= msdbrw_write) { - writedb(statusfile,0,1); + writedb(statusfile, wdb_must_sync); for (i=0; i<cdn; i++) { strcpy(updatefnrest, cdlist[i]->d_name); @@ -301,7 +301,7 @@ void modstatdb_checkpoint(void) { int i; assert(cstatus >= msdbrw_write); - writedb(statusfile,0,1); + writedb(statusfile, wdb_must_sync); for (i=0; i<nextupdate; i++) { sprintf(updatefnrest, IMPORTANTFMT, i); @@ -318,7 +318,7 @@ void modstatdb_checkpoint(void) { void modstatdb_shutdown(void) { if (cflags >= msdbrw_available_write) - writedb(availablefile, 1, 0); + writedb(availablefile, wdb_dump_available); switch (cstatus) { case msdbrw_write: diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h index 1ddde86..353183f 100644 --- a/lib/dpkg/dpkg-db.h +++ b/lib/dpkg/dpkg-db.h @@ -299,7 +299,14 @@ const char *versiondescribe(const struct versionrevision*, void writerecord(FILE*, const char*, const struct pkginfo *, const struct pkgbin *); -void writedb(const char *filename, bool available, bool mustsync); +enum writedb_flags { + /* Dump ‘available’ in-core structures, not ‘status’. */ + wdb_dump_available = 001, + /* Must sync the written file. */ + wdb_must_sync = 002, +}; + +void writedb(const char *filename, enum writedb_flags flags); /* Note: The varbufs must have been initialized and will not be * NUL-terminated. */ diff --git a/lib/dpkg/dump.c b/lib/dpkg/dump.c index 4f44543..0e7d682 100644 --- a/lib/dpkg/dump.c +++ b/lib/dpkg/dump.c @@ -399,7 +399,7 @@ writerecord(FILE *file, const char *filename, } void -writedb(const char *filename, bool available, bool mustsync) +writedb(const char *filename, enum writedb_flags flags) { static char writebuf[8192]; @@ -412,7 +412,7 @@ writedb(const char *filename, bool available, bool mustsync) struct varbuf vb = VARBUF_INIT; int old_umask; - which = available ? "available" : "status"; + which = (flags & wdb_dump_available) ? "available" : "status"; m_asprintf(&oldfn, "%s%s", filename, OLDDBEXT); m_asprintf(&newfn, "%s%s", filename, NEWDBEXT); @@ -427,7 +427,7 @@ writedb(const char *filename, bool available, bool mustsync) it = pkg_db_iter_new(); while ((pigp = pkg_db_iter_next(it)) != NULL) { - pifp= available ? &pigp->available : &pigp->installed; + pifp = (flags & wdb_dump_available) ? &pigp->available : &pigp->installed; /* Don't dump records which have no useful content. */ if (!pkg_is_informative(pigp, pifp)) continue; @@ -441,7 +441,7 @@ writedb(const char *filename, bool available, bool mustsync) } pkg_db_iter_free(it); varbuf_destroy(&vb); - if (mustsync) { + if (flags & wdb_must_sync) { if (fflush(file)) ohshite(_("failed to flush %s database to '%.250s'"), which, filename); if (fsync(fileno(file))) @@ -458,7 +458,7 @@ writedb(const char *filename, bool available, bool mustsync) ohshite(_("failed to install '%.250s' as '%.250s' containing %s database"), newfn, filename, which); - if (mustsync) + if (flags & wdb_must_sync) dir_sync_path_parent(filename); free(newfn); diff --git a/src/update.c b/src/update.c index 76b2372..227c9d1 100644 --- a/src/update.c +++ b/src/update.c @@ -90,7 +90,7 @@ updateavailable(const char *const *argv) NULL); if (!f_noact) { - writedb(availfile, 1, 0); + writedb(availfile, wdb_dump_available); modstatdb_unlock(); } -- dpkg's main repository -- To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org