[pacman-dev] [PATCH] Copy pmdelta_t objects in _alpm_pkg_dup().

Nathan Jones nathanj at insightbb.com
Mon Oct 29 18:00:31 EDT 2007


_alpm_pkg_dup() should create copies of all objects inside the pmpkg_t
struct. I missed this function when adding the delta list to pmpkg_t.

Signed-off-by: Nathan Jones <nathanj at insightbb.com>
---
 lib/libalpm/package.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 4f6f5a9..7829d48 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -49,6 +49,7 @@
 #include "provide.h"
 #include "handle.h"
 #include "alpm.h"
+#include "delta.h"
 
 /** \addtogroup alpm_packages Package Functions
  * @brief Functions to manipulate libalpm packages
@@ -689,6 +690,7 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version)
 pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
 {
 	pmpkg_t* newpkg;
+	alpm_list_t *deltas;
 
 	ALPM_LOG_FUNC;
 
@@ -708,6 +710,23 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
 	newpkg->groups     = alpm_list_strdup(alpm_pkg_get_groups(pkg));
 	newpkg->provides   = alpm_list_strdup(alpm_pkg_get_provides(pkg));
 	newpkg->replaces   = alpm_list_strdup(alpm_pkg_get_replaces(pkg));
+
+	/* copy all the delta objects */
+	newpkg->deltas = NULL;
+	deltas = alpm_pkg_get_deltas(pkg);
+	while(deltas) {
+		pmdelta_t *d = malloc(sizeof(pmdelta_t));
+
+		if(d == NULL) {
+			_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdelta_t));
+			RET_ERR(PM_ERR_MEMORY, NULL);
+		}
+
+		memcpy(d, alpm_list_getdata(deltas), sizeof(pmdelta_t));
+		newpkg->deltas = alpm_list_add(newpkg->deltas, d);
+		deltas = alpm_list_next(deltas);
+	}
+
 	/* internal */
 	if(newpkg->origin == PKG_FROM_FILE) {
 		newpkg->origin_data.file = strdup(pkg->origin_data.file);
-- 
1.5.3.4




More information about the pacman-dev mailing list