[pacman-dev] [PATCH] Improve changelog handling

Andrew Fyfe andrew at neptune-one.net
Sat Dec 8 14:28:05 EST 2007


Xavier wrote:
> diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
> index 172456d..3d7e74d 100644
> --- a/lib/libalpm/package.c
> +++ b/lib/libalpm/package.c
> @@ -491,6 +491,86 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t *pkg)
>  	return pkg->backup;
>  }
>  
> +char 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;
> +	char clfile[PATH_MAX];
> +	FILE *fp = NULL;
> +	struct archive *archive = NULL;
> +	struct archive_entry *entry;
> +	char *changelog = NULL, *p = NULL;
> +	int bufsize = 512, size = 0, n = 0;
> +	int done = 0, found = 0;
> +
> +	if(pkg->origin == PKG_FROM_CACHE) {
> +		snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog",
> +				alpm_option_get_dbpath(),
> +				alpm_db_get_name(handle->db_local),
> +				alpm_pkg_get_name(pkg),
> +				alpm_pkg_get_version(pkg));
> +		fp = fopen(clfile, "r");
> +		if(fp != NULL) {
> +			found = 1;
> +		}
> +	} 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) {
> +				found = 1;
> +				break;
> +			}
> +		}
> +	}
> +
> +	if(!found) {
> +		return(NULL);

You're missing an archive_read_finish(archive) before the return.

Andrew




More information about the pacman-dev mailing list