This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=ec28c134d983d65f5c5cebb1f8f36cfe884758be commit ec28c134d983d65f5c5cebb1f8f36cfe884758be Author: Guillem Jover <[email protected]> AuthorDate: Sun Nov 27 13:39:48 2022 +0100 dpkg-divert: Load database only from within relevant actions This moves this action specific code from the generic main() handling, so that we can add new actions that might not need the database, and we do not inflict unnecessary slowdowns. Changelog: internal --- src/divert/main.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/divert/main.c b/src/divert/main.c index dae3ba227..7d739e845 100644 --- a/src/divert/main.c +++ b/src/divert/main.c @@ -482,6 +482,9 @@ diversion_add(const char *const *argv) diversion_check_filename(filename); + modstatdb_open(msdbrw_readonly); + ensure_diversions(); + file_init(&file_from, filename); file_stat(&file_from); @@ -522,6 +525,8 @@ diversion_add(const char *const *argv) file_destroy(&file_from); file_destroy(&file_to); + modstatdb_shutdown(); + return 0; } @@ -571,6 +576,8 @@ diversion_add(const char *const *argv) file_destroy(&file_from); file_destroy(&file_to); + modstatdb_shutdown(); + return 0; } @@ -622,6 +629,9 @@ diversion_remove(const char *const *argv) diversion_check_filename(filename); + modstatdb_open(msdbrw_readonly); + ensure_diversions(); + namenode = fsys_hash_find_node(filename, FHFF_NONE); if (namenode == NULL || namenode->divert == NULL || @@ -629,6 +639,7 @@ diversion_remove(const char *const *argv) if (opt_verbose > 0) printf(_("No diversion '%s', none removed.\n"), diversion_current(filename)); + modstatdb_shutdown(); return 0; } @@ -661,6 +672,7 @@ diversion_remove(const char *const *argv) if (opt_verbose > 0) printf(_("Ignoring request to remove shared diversion '%s'.\n"), diversion_describe(contest)); + modstatdb_shutdown(); return 0; } @@ -685,6 +697,8 @@ diversion_remove(const char *const *argv) file_destroy(&file_from); file_destroy(&file_to); + modstatdb_shutdown(); + return 0; } @@ -696,6 +710,9 @@ diversion_list(const char *const *argv) struct glob_node *glob_list = NULL; const char *pattern; + modstatdb_open(msdbrw_readonly); + ensure_diversions(); + while ((pattern = *argv++)) glob_list_prepend(&glob_list, m_strdup(pattern)); @@ -729,6 +746,8 @@ diversion_list(const char *const *argv) glob_list_free(glob_list); + modstatdb_shutdown(); + return 0; } @@ -743,6 +762,9 @@ diversion_truename(const char *const *argv) diversion_check_filename(filename); + modstatdb_open(msdbrw_readonly); + ensure_diversions(); + namenode = fsys_hash_find_node(filename, FHFF_NONE); /* Print the given name if file is not diverted. */ @@ -751,6 +773,8 @@ diversion_truename(const char *const *argv) else printf("%s\n", filename); + modstatdb_shutdown(); + return 0; } @@ -765,6 +789,9 @@ diversion_listpackage(const char *const *argv) diversion_check_filename(filename); + modstatdb_open(msdbrw_readonly); + ensure_diversions(); + namenode = fsys_hash_find_node(filename, FHFF_NONE); /* Print nothing if file is not diverted. */ @@ -778,6 +805,8 @@ diversion_listpackage(const char *const *argv) else printf("%s\n", namenode->divert->pkgset->name); + modstatdb_shutdown(); + return 0; } @@ -862,13 +891,8 @@ main(int argc, const char * const *argv) if (!cipaction) setaction(&cmdinfo_add, NULL); - modstatdb_open(msdbrw_readonly); - ensure_diversions(); - ret = cipaction->action(argv); - modstatdb_shutdown(); - dpkg_program_done(); dpkg_locales_done(); -- Dpkg.Org's dpkg

