[pacman-dev] [PATCH] Improve changelog handling

Xavier shiningxc at gmail.com
Sat Dec 8 18:43:37 EST 2007


On Sat, Dec 08, 2007 at 02:47:23AM +1000, Allan McRae wrote:
>  From 47affca982ec2d449bd6d96846172052dbdd3da6 Mon Sep 17 00:00:00 2001
> From: Allan McRae <mcrae_allan at hotmail.com>
> Date: Sat, 8 Dec 2007 02:35:00 +1000
> Subject: [PATCH] Improve changelog handling
> 
> Allows dumping of changelog for both installed packages and from package 
> files
> (See FS#7321). Moves querying of changelog file in alpm backend.
> 
> Signed-off-by: Allan McRae <mcrae_allan at hotmail.com>
> ---
>  lib/libalpm/alpm.h    |    1 +
>  lib/libalpm/package.c |   71 
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  src/pacman/package.c  |   33 ++++++++++------------
>  src/pacman/package.h  |    2 +-
>  src/pacman/query.c    |    9 +-----
>  5 files changed, 89 insertions(+), 27 deletions(-)
> 
> diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
> index 1e18ad9..7f6c9eb 100644
> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -216,6 +216,7 @@ alpm_list_t *alpm_pkg_get_deltas(pmpkg_t *pkg);
>  alpm_list_t *alpm_pkg_get_replaces(pmpkg_t *pkg);
>  alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
>  alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
> +alpm_list_t *alpm_pkg_get_changelog(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);
> diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
> index 172456d..bbdb95d 100644
> --- a/lib/libalpm/package.c
> +++ b/lib/libalpm/package.c
> @@ -491,6 +491,77 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t 
> *pkg)
>      return pkg->backup;
>  }
>  
> +alpm_list_t SYMEXPORT *alpm_pkg_get_changelog(pmpkg_t *pkg)
> +{
> +    ALPM_LOG_FUNC;
> +
> +    /* Sanity checks */
> +    ASSERT(handle != NULL, return(NULL));
> +    ASSERT(pkg != NULL, return(NULL));
> +   
> +    int ret = ARCHIVE_OK;
> +    alpm_list_t *cl = NULL;   
> +    char clfile[PATH_MAX];
> +    char *tmpfile = NULL;
> +    struct archive *archive;
> +    struct archive_entry *entry;
> +    int fd = -1;
> +    char line[PATH_MAX];
> +   
> +    if(pkg->origin == PKG_FROM_CACHE) {
> +        snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog",
> +                alpm_option_get_dbpath(),
> +                alpm_db_get_name(alpm_db_register_local()),

I believe you should use handle->db_local here rather than
alpm_db_register_local();

> +                alpm_pkg_get_name(pkg),
> +                alpm_pkg_get_version(pkg));
> +    } else if(pkg->origin == PKG_FROM_FILE) {
> +        const char *pkgfile = pkg->origin_data.file;
> +
> +        if((archive = archive_read_new()) == NULL) {
> +            RET_ERR(PM_ERR_LIBARCHIVE_ERROR, NULL);
> +        }
> +   
> +        archive_read_support_compression_all(archive);
> +        archive_read_support_format_all(archive);
> +   
> +        if (archive_read_open_filename(archive, pkgfile,
> +                    ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
> +            RET_ERR(PM_ERR_PKG_OPEN, NULL);
> +        }
> +       
> +        while((ret = archive_read_next_header(archive, &entry)) == 
> ARCHIVE_OK) {
> +            const char *entry_name = archive_entry_pathname(entry);
> +
> +            if(strcmp(entry_name, ".CHANGELOG") == 0) {       
> +                tmpfile = strdup("/tmp/alpm_XXXXXX");
> +                fd = mkstemp(tmpfile);
> +                archive_read_data_into_fd(archive, fd);
> +                break;
> +            }
> +        }
> +        snprintf(clfile, PATH_MAX, "%s", tmpfile);
> +    }
> +

You probably got this part from _alpm_pkg_load, I guess it's alright (except
you probably want to add an archive_read_finish(archive); there).

But you could also use _alpm_unpack, like in _alpm_runscriptlet.

Btw, I couldn't get your patch to apply cleanly, because of many line breaks.
So I started rewriting it from the start, but in the same time, I wanted to
experiment reading directly from the archive, which resulted in the patch I
submitted somewhere else in this thread.
I don't know if it's better or not, but if it is, all the credits still go to
you, for looking at the problem in the first place, and providing a good
patch to work with. So thanks again.




More information about the pacman-dev mailing list