[pacman-dev] [PATCH] Change -z|--showsize flag to ShowSize pacman.conf option
Also, some duplicate printf lines related to the ShowSize option were cleaned up. Dan, I created this diff against your tree not the official one, if it makes a difference when applying. Signed-off-by: Nathan Jones <nathanj@insightbb.com> --- doc/pacman.conf.5 | 4 ++++ lib/libalpm/alpm.c | 3 +++ lib/libalpm/alpm.h | 3 +++ lib/libalpm/handle.c | 6 ++++++ lib/libalpm/handle.h | 1 + src/pacman/conf.h | 1 - src/pacman/pacman.c | 4 ---- src/pacman/query.c | 12 +++++------- src/pacman/sync.c | 15 ++++++--------- src/pacman/util.c | 3 ++- 10 files changed, 30 insertions(+), 22 deletions(-) diff --git a/doc/pacman.conf.5 b/doc/pacman.conf.5 index 15f7b95..f7304aa 100644 --- a/doc/pacman.conf.5 +++ b/doc/pacman.conf.5 @@ -85,6 +85,10 @@ Log action messages through \fBsyslog()\fP. This will insert log entries into .TP .B LogFile = \fI/path/to/file\fP Log actions directly to a file. Default is \fI/var/log/pacman.log\fP. +.TP +.B ShowSize +Display the size of individual packages for \fB--sync\fP and \fB--query\fP +modes. .SH REPOSITORY SECTIONS Each repository section defines a section name and at least one location where diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 4239430..db66092 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -959,6 +959,9 @@ int SYMEXPORT alpm_parse_config(char *file, alpm_cb_db_register callback, const } else if(strcmp(origkey, "UseColor") == 0 || strcmp(key, "USECOLOR") == 0) { alpm_option_set_usecolor(1); _alpm_log(PM_LOG_DEBUG, _("config: usecolor")); + } else if(strcmp(origkey, "ShowSize") == 0 || strcmp(key, "SHOWSIZE") == 0) { + alpm_option_set_showsize(1); + _alpm_log(PM_LOG_DEBUG, _("config: showsize")); } else { RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1); } diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e2d2b0e..047048c 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -144,6 +144,9 @@ void alpm_option_set_needles(alpm_list_t *needles); unsigned short alpm_option_get_usecolor(); void alpm_option_set_usecolor(unsigned short usecolor); +unsigned short alpm_option_get_showsize(); +void alpm_option_set_showsize(unsigned short showsize); + pmdb_t *alpm_option_get_localdb(); alpm_list_t *alpm_option_get_syncdbs(); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 47abcb3..39caaa9 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -137,6 +137,7 @@ const char *alpm_option_get_xfercommand() { return handle->xfercommand; } unsigned short alpm_option_get_nopassiveftp() { return handle->nopassiveftp; } unsigned short SYMEXPORT alpm_option_get_chomp() { return handle->chomp; } unsigned short alpm_option_get_usecolor() { return handle->use_color; } +unsigned short SYMEXPORT alpm_option_get_showsize() { return handle->showsize; } pmdb_t SYMEXPORT *alpm_option_get_localdb() { return handle->db_local; } alpm_list_t SYMEXPORT *alpm_option_get_syncdbs() @@ -297,4 +298,9 @@ void alpm_option_set_usecolor(unsigned short usecolor) handle->use_color = usecolor; } +void alpm_option_set_showsize(unsigned short showsize) +{ + handle->showsize = showsize; +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 0790ad1..b80f751 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -65,6 +65,7 @@ typedef struct _pmhandle_t { unsigned short nopassiveftp; /* Don't use PASV ftp connections */ unsigned short chomp; /* I Love Candy! */ unsigned short use_color; /* enable colorful output */ + unsigned short showsize; /* Show individual package sizes */ } pmhandle_t; extern pmhandle_t *handle; diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 11aa41b..4fff0ab 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -54,7 +54,6 @@ typedef struct __config_t { pmtransflag_t flags; unsigned short noask; unsigned int ask; - unsigned short showsize; } config_t; config_t *config_new(void); diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index fe70ea1..50265e4 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -131,7 +131,6 @@ static void usage(int op, char *myname) printf(_(" -p, --file <package> query a package file instead of the database\n")); printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n")); printf(_(" -u, --upgrades list all packages that can be upgraded\n")); - printf(_(" -z, --showsize display installed size of each package\n")); } else if(op == PM_OP_SYNC) { printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); @@ -147,7 +146,6 @@ static void usage(int op, char *myname) printf(_(" -u, --sysupgrade upgrade all packages that are out of date\n")); printf(_(" -w, --downloadonly download packages but do not install/upgrade anything\n")); printf(_(" -y, --refresh download fresh package databases from the server\n")); - printf(_(" -z, --showsize display download size of each package\n")); printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n")); } printf(_(" --config <path> set an alternate configuration file\n")); @@ -293,7 +291,6 @@ static int parseargs(int argc, char *argv[]) {"verbose", no_argument, 0, 'v'}, {"downloadonly", no_argument, 0, 'w'}, {"refresh", no_argument, 0, 'y'}, - {"showsize", no_argument, 0, 'z'}, {"noconfirm", no_argument, 0, 1000}, {"config", required_argument, 0, 1001}, {"ignore", required_argument, 0, 1002}, @@ -426,7 +423,6 @@ static int parseargs(int argc, char *argv[]) config->flags |= PM_TRANS_FLAG_NOCONFLICTS; break; case 'y': (config->op_s_sync)++; break; - case 'z': config->showsize = 1; break; case '?': return(1); default: return(1); } diff --git a/src/pacman/query.c b/src/pacman/query.c index bb4cfb9..aa360f1 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -146,16 +146,14 @@ int pacman_query(alpm_list_t *targets) alpm_list_t *grp; pmpkg_t *pkg = alpm_list_getdata(i); - /* print the package size with the output if -z option passed */ - if(config->showsize) { + printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); + + /* print the package size with the output if ShowSize option set */ + if(alpm_option_get_showsize()) { /* Convert byte size to MB */ double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); - printf("local/%s %s [%.2f MB]", alpm_pkg_get_name(pkg), - alpm_pkg_get_version(pkg), mbsize); - } else { - printf("local/%s %s", alpm_pkg_get_name(pkg), - alpm_pkg_get_version(pkg)); + printf(" [%.2f MB]", mbsize); } if((grp = alpm_pkg_get_groups(pkg)) != NULL) { diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 4f11bb4..bb2b977 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -251,18 +251,15 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) alpm_list_t *grp; pmpkg_t *pkg = alpm_list_getdata(j); - /* print the package size with the output if -z option passed */ - if(config->showsize) { + printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg), + alpm_pkg_get_version(pkg)); + + /* print the package size with the output if ShowSize option set */ + if(alpm_option_get_showsize()) { /* Convert byte size to MB */ double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); - printf("%s/%s %s [%.2f MB]", alpm_db_get_name(db), - alpm_pkg_get_name(pkg), - alpm_pkg_get_version(pkg), mbsize); - } else { - printf("%s/%s %s", alpm_db_get_name(db), - alpm_pkg_get_name(pkg), - alpm_pkg_get_version(pkg)); + printf(" [%.2f MB]", mbsize); } if((grp = alpm_pkg_get_groups(pkg)) != NULL) { diff --git a/src/pacman/util.c b/src/pacman/util.c index f38be60..7b7ec0b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -294,7 +294,8 @@ void display_targets(alpm_list_t *syncpkgs) size += dispsize; isize += alpm_pkg_get_isize(pkg); - if(config->showsize) { + /* print the package size with the output if ShowSize option set */ + if(alpm_option_get_showsize()) { /* Convert byte size to MB */ mbdispsize = dispsize / (1024.0 * 1024.0); -- 1.5.1.3
On 5/14/07, Nathan Jones <nathanj@insightbb.com> wrote:
Also, some duplicate printf lines related to the ShowSize option were cleaned up.
Dan, I created this diff against your tree not the official one, if it makes a difference when applying.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
Well this got lost in the email box a while back. Applying now and checking, it'll eventually get pushed to the main tree. -Dan
On 6/1/07, Dan McGee <dpmcgee@gmail.com> wrote:
On 5/14/07, Nathan Jones <nathanj@insightbb.com> wrote:
Also, some duplicate printf lines related to the ShowSize option were cleaned up.
Dan, I created this diff against your tree not the official one, if it makes a difference when applying.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
Well this got lost in the email box a while back. Applying now and checking, it'll eventually get pushed to the main tree.
-Dan
OK, pushed to my working branch and all looks good to go. While doing this, I noticed how awful our pacman.conf parsing really is. We *silently* fail on any unrecognized option (ex. ShowSize with a pacman that doesn't support it), and that makes it terribly hard for users to debug without using the --debug flag. Even then it isn't easy. Aaron and I both want to move this config file parsing to the front end; any objections to this? It will be quite a change, but we can make it much more robust while moving it. Is anyone familiar with how config file parsing is done by other programs? It seems like a very manual process currently, and a malformed config file brings pacman down. I also think we should try to continue when we encounter an unrecognized option. -Dan
On 6/1/07, Dan McGee <dpmcgee@gmail.com> wrote:
Aaron and I both want to move this config file parsing to the front end; any objections to this? It will be quite a change, but we can make it much more robust while moving it. Is anyone familiar with how config file parsing is done by other programs? It seems like a very manual process currently, and a malformed config file brings pacman down. I also think we should try to continue when we encounter an unrecognized option.
What do you mean "other programs"? As in, an elegant parsing system? Or how other apps parse pacman.conf?
2007/6/1, Aaron Griffin <aaronmgriffin@gmail.com>:
On 6/1/07, Dan McGee <dpmcgee@gmail.com> wrote:
Aaron and I both want to move this config file parsing to the front end; any objections to this? It will be quite a change, but we can make it much more robust while moving it. Is anyone familiar with how config file parsing is done by other programs? It seems like a very manual process currently, and a malformed config file brings pacman down. I also think we should try to continue when we encounter an unrecognized option.
What do you mean "other programs"? As in, an elegant parsing system? Or how other apps parse pacman.conf?
I'm suggesting to use 3rd party library for parsing. I see 2 choices: 1) iniparser there is nice console app that can be used by shell scripts to parse config (made by James): http://archlinux.org/~james/projects/network/iniread-0.1/ usage example: http://archlinux.org/pipermail/arch-dev-public/2007-April/000415.html 2) libconfuse this one has nice validation features -- Roman Kyrylych (Роман Кирилич)
participants (4)
-
Aaron Griffin
-
Dan McGee
-
Nathan Jones
-
Roman Kyrylych