[pacman-dev] [PATCH 4/4] Add download size to target list.

Dan McGee dpmcgee at gmail.com
Mon Oct 15 22:59:07 EDT 2007


On 10/15/07, Nathan Jones <nathanj at insightbb.com> wrote:
> This displays the download size, taking into account delta files and
> cached files.
>
> This closes FS#4182.
>
> Signed-off-by: Nathan Jones <nathanj at insightbb.com>
> ---
>  lib/libalpm/alpm.h |    2 ++
>  lib/libalpm/sync.c |   34 ++++++++++++++++++++++++++++++++++
>  src/pacman/query.c |    2 +-
>  src/pacman/sync.c  |    2 +-
>  src/pacman/util.c  |   22 +++++++---------------
>  src/pacman/util.h  |    2 +-
>  6 files changed, 46 insertions(+), 18 deletions(-)
>
> diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
> index 85c0905..fd18a01 100644
> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -215,6 +215,8 @@ alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
>  alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
>  unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
>
> +unsigned long alpm_pkg_download_size(pmpkg_t *newpkg, pmdb_t *db_local);
> +
>  /*
>   * Deltas
>   */
> diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
> index 8aa197d..c108f81 100644
> --- a/lib/libalpm/sync.c
> +++ b/lib/libalpm/sync.c
> @@ -745,6 +745,40 @@ static alpm_list_t *pkg_upgrade_delta_path(pmpkg_t *newpkg, pmdb_t *db_local)
>         return NULL;
>  }
>
> +/** Returns the size of the files that will be downloaded to install a
> + * package.
> + *
> + * @param newpkg the new package to upgrade to
> + * @param db_local the local database
> + *
> + * @return the size of the download
> + */
> +unsigned long SYMEXPORT alpm_pkg_download_size(pmpkg_t *newpkg, pmdb_t *db_local)
> +{
> +       char *fpath = _alpm_filecache_find(alpm_pkg_get_filename(newpkg));
> +       unsigned long size = 0;

We probably should be using a size_t/ssize_t or whatever we are
supposed to here, but that would be a whole different patch as we
already use unsigned long elsewhere.

> +
> +       if(fpath) {
> +               size = 0;
> +       } else if(handle->usedelta) {
> +               alpm_list_t *deltas = pkg_upgrade_delta_path(newpkg, db_local);
> +
> +               if(deltas) {
> +                       size = _alpm_delta_path_size_uncached(deltas);

Does this account for the delta is greater than 0.7 of the size case?

> +               } else {
> +                       size = alpm_pkg_get_size(newpkg);
> +               }
> +
> +               alpm_list_free(deltas);
> +       } else {
> +               size = alpm_pkg_get_size(newpkg);
> +       }
> +
> +       FREE(fpath);
> +
> +       return(size);
> +}
> +
>  int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
>  {
>         alpm_list_t *i, *j, *files = NULL;
> diff --git a/src/pacman/query.c b/src/pacman/query.c
> index 4e4002c..8a01d82 100644
> --- a/src/pacman/query.c
> +++ b/src/pacman/query.c
> @@ -219,7 +219,7 @@ static int query_upgrades(void)
>         printf(_("Checking for package upgrades... \n"));
>
>         if((syncpkgs = alpm_db_get_upgrades()) != NULL) {
> -               display_targets(syncpkgs);
> +               display_targets(syncpkgs, db_local);
>                 return(0);
>         }
>
> diff --git a/src/pacman/sync.c b/src/pacman/sync.c
> index 6a7d50e..bf6eed1 100644
> --- a/src/pacman/sync.c
> +++ b/src/pacman/sync.c
> @@ -601,7 +601,7 @@ int sync_trans(alpm_list_t *targets, int sync_only)
>         if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) {
>                 int confirm;
>
> -               display_targets(packages);
> +               display_targets(packages, db_local);
>                 printf("\n");
>
>                 if(config->op_s_downloadonly) {
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 2c00753..8b6079d 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -329,14 +329,15 @@ void list_display(const char *title, const alpm_list_t *list)
>   * retrieved from a transaction object
>   */
>  /* TODO move to output.c? or just combine util and output */
> -void display_targets(const alpm_list_t *syncpkgs)
> +void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local)
>  {
>         char *str;
>         const alpm_list_t *i, *j;
>         alpm_list_t *targets = NULL, *to_remove = NULL;
>         /* TODO these are some messy variable names */
> -       unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0;
> -       double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0, mbdispsize = 0.0;
> +       unsigned long size = 0, isize = 0, rsize = 0, dispsize = 0, dlsize = 0;
> +       double mbsize = 0.0, mbisize = 0.0, mbrsize = 0.0, mbdispsize = 0.0,
> +                                mbdlsize = 0.0;
>
>         for(i = syncpkgs; i; i = alpm_list_next(i)) {
>                 pmsyncpkg_t *sync = alpm_list_getdata(i);
> @@ -361,6 +362,7 @@ void display_targets(const alpm_list_t *syncpkgs)
>
>                 dispsize = alpm_pkg_get_size(pkg);
>                 size += dispsize;
> +               dlsize += alpm_pkg_download_size(pkg, db_local);
>                 isize += alpm_pkg_get_isize(pkg);
>
>                 /* print the package size with the output if ShowSize option set */
> @@ -381,6 +383,7 @@ void display_targets(const alpm_list_t *syncpkgs)
>         mbsize = size / (1024.0 * 1024.0);
>         mbisize = isize / (1024.0 * 1024.0);
>         mbrsize = rsize / (1024.0 * 1024.0);
> +       mbdlsize = dlsize / (1024.0 * 1024.0);
>
>         /* start displaying information */
>         printf("\n");
> @@ -390,28 +393,17 @@ void display_targets(const alpm_list_t *syncpkgs)
>                 printf("\n");
>                 FREELIST(to_remove);
>
> -               /* round up if size is really small */
> -               if(mbrsize < 0.1) {
> -                       mbrsize = 0.1;
> -               }

Any reason for removing this?

>                 printf(_("Total Removed Size:   %.2f MB\n"), mbrsize);
>         }
>
>         list_display(_("Targets:"), targets);
>         printf("\n");
>
> -       /* round up if size is really small */
> -       if(mbsize < 0.1) {
> -               mbsize = 0.1;
> -       }

Echo what I said above.

>         printf(_("Total Package Size:   %.2f MB\n"), mbsize);
> +       printf(_("Total Download Size   %.2f MB\n"), mbdlsize);
>
>         /* TODO because all pkgs don't include isize, this is a crude hack */
>         if(mbisize > mbsize) {
> -               /*round up if size is really small */
> -               if(mbisize < 0.1) {
> -                       mbisize = 0.1;
> -               }

See above.

>                 printf(_("Total Installed Size:   %.2f MB\n"), mbisize);
>         }
>
> diff --git a/src/pacman/util.h b/src/pacman/util.h
> index f3171ca..876f817 100644
> --- a/src/pacman/util.h
> +++ b/src/pacman/util.h
> @@ -47,7 +47,7 @@ char *strtoupper(char *str);
>  char *strtrim(char *str);
>  char *strreplace(const char *str, const char *needle, const char *replace);
>  void list_display(const char *title, const alpm_list_t *list);
> -void display_targets(const alpm_list_t *syncpkgs);
> +void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local);
>  int yesno(char *fmt, ...);
>  int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
>  int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
> --
> 1.5.3.4




More information about the pacman-dev mailing list