summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-02-15 20:17:57 -0600
committerDan McGee <dan@archlinux.org>2008-04-26 11:30:12 -0500
commit30bdf94c2b444ff475a32e7b0c569e8c3cf05797 (patch)
tree408802e82996905879372deabee8123c5fa5d98e /lib
parentff9744aa1f9d3da380e722fd44a07b8c8a68d101 (diff)
downloadpacman-30bdf94c2b444ff475a32e7b0c569e8c3cf05797.tar.xz
Rework delta struct and modify code accordingly
Start to move the delta struct away from an assumed package name scheme and towards something that is package (or even filename) agnostic. This will allow us much greater flexibility in the usage of deltas (maybe even sync DBs some day) as well as allowing code outside of delta.h/delta.c to be much cleaner with less of a need for snprintf() calls. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm.h4
-rw-r--r--lib/libalpm/delta.c85
-rw-r--r--lib/libalpm/delta.h15
-rw-r--r--lib/libalpm/sync.c31
4 files changed, 67 insertions, 68 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index a7ea0630..e5445d0d 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -229,10 +229,12 @@ unsigned long alpm_pkg_download_size(pmpkg_t *newpkg, pmdb_t *db_local);
*/
const char *alpm_delta_get_from(pmdelta_t *delta);
+const char *alpm_delta_get_from_md5sum(pmdelta_t *delta);
const char *alpm_delta_get_to(pmdelta_t *delta);
-unsigned long alpm_delta_get_size(pmdelta_t *delta);
+const char *alpm_delta_get_to_md5sum(pmdelta_t *delta);
const char *alpm_delta_get_filename(pmdelta_t *delta);
const char *alpm_delta_get_md5sum(pmdelta_t *delta);
+unsigned long alpm_delta_get_size(pmdelta_t *delta);
/*
* Groups
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index e9870c8c..12fb9bd7 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -36,60 +36,50 @@
const char SYMEXPORT *alpm_delta_get_from(pmdelta_t *delta)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(delta != NULL, return(NULL));
-
return(delta->from);
}
-const char SYMEXPORT *alpm_delta_get_to(pmdelta_t *delta)
+const char SYMEXPORT *alpm_delta_get_from_md5sum(pmdelta_t *delta)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(delta != NULL, return(NULL));
+ return(delta->from_md5);
+}
+const char SYMEXPORT *alpm_delta_get_to(pmdelta_t *delta)
+{
+ ASSERT(delta != NULL, return(NULL));
return(delta->to);
}
-unsigned long SYMEXPORT alpm_delta_get_size(pmdelta_t *delta)
+const char SYMEXPORT *alpm_delta_get_to_md5sum(pmdelta_t *delta)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(delta != NULL, return(-1));
-
- return(delta->size);
+ ASSERT(delta != NULL, return(NULL));
+ return(delta->to_md5);
}
const char SYMEXPORT *alpm_delta_get_filename(pmdelta_t *delta)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(delta != NULL, return(NULL));
-
- return(delta->filename);
+ return(delta->delta);
}
const char SYMEXPORT *alpm_delta_get_md5sum(pmdelta_t *delta)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(delta != NULL, return(NULL));
+ return(delta->delta_md5);
+}
- return(delta->md5sum);
+unsigned long SYMEXPORT alpm_delta_get_size(pmdelta_t *delta)
+{
+ ASSERT(delta != NULL, return(-1));
+ return(delta->delta_size);
}
/** @} */
/** Calculates the combined size of a list of delta files.
- *
* @param deltas the list of pmdelta_t * objects
- *
* @return the combined size
*/
unsigned long _alpm_delta_path_size(alpm_list_t *deltas)
@@ -99,7 +89,7 @@ unsigned long _alpm_delta_path_size(alpm_list_t *deltas)
while(dlts) {
pmdelta_t *d = alpm_list_getdata(dlts);
- sum += d->size;
+ sum += d->delta_size;
dlts = alpm_list_next(dlts);
}
@@ -109,9 +99,7 @@ unsigned long _alpm_delta_path_size(alpm_list_t *deltas)
/** Calculates the combined size of a list of delta files that are not
* in the cache.
- *
* @param deltas the list of pmdelta_t * objects
- *
* @return the combined size
*/
unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas)
@@ -121,10 +109,10 @@ unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas)
while(dlts) {
pmdelta_t *d = alpm_list_getdata(dlts);
- char *fname = _alpm_filecache_find(d->filename);
+ char *fname = _alpm_filecache_find(d->delta);
if(!fname) {
- sum += d->size;
+ sum += d->delta_size;
}
FREE(fname);
@@ -136,17 +124,13 @@ unsigned long _alpm_delta_path_size_uncached(alpm_list_t *deltas)
}
/** Calculates the shortest path from one version to another.
- *
* The shortest path is defined as the path with the smallest combined
* size, not the length of the path.
- *
* The algorithm is based on Dijkstra's shortest path algorithm.
- *
* @param deltas the list of pmdelta_t * objects that a package has
* @param from the version to start from
* @param to the version to end at
* @param path the current path
- *
* @return the list of pmdelta_t * objects that has the smallest size.
* NULL (the empty list) is returned if there is no path between the
* versions.
@@ -200,14 +184,11 @@ static alpm_list_t *shortest_delta_path(alpm_list_t *deltas,
}
/** Calculates the shortest path from one version to another.
- *
* The shortest path is defined as the path with the smallest combined
* size, not the length of the path.
- *
* @param deltas the list of pmdelta_t * objects that a package has
* @param from the version to start from
* @param to the version to end at
- *
* @return the list of pmdelta_t * objects that has the smallest size.
* NULL (the empty list) is returned if there is no path between the
* versions.
@@ -223,13 +204,13 @@ alpm_list_t *_alpm_shortest_delta_path(alpm_list_t *deltas, const char *from,
}
/** Parses the string representation of a pmdelta_t object.
- *
* This function assumes that the string is in the correct format.
- *
+ * This format is as follows:
+ * $oldfile $oldmd5 $newfile $newmd5 $deltafile $deltamd5 $deltasize
* @param line the string to parse
- *
* @return A pointer to the new pmdelta_t object
*/
+/* TODO this does not really belong here, but in a parsing lib */
pmdelta_t *_alpm_delta_parse(char *line)
{
pmdelta_t *delta;
@@ -245,19 +226,29 @@ pmdelta_t *_alpm_delta_parse(char *line)
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
+ STRDUP(delta->from_md5, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
+
+ tmp2 = tmp;
+ tmp = strchr(tmp, ' ');
+ *(tmp++) = '\0';
STRDUP(delta->to, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- delta->size = atol(tmp2);
+ STRDUP(delta->to_md5, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
+
+ tmp2 = tmp;
+ tmp = strchr(tmp, ' ');
+ *(tmp++) = '\0';
+ STRDUP(delta->delta, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- STRDUP(delta->filename, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(delta->delta_md5, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(delta->md5sum, tmp, RET_ERR(PM_ERR_MEMORY, NULL));
+ delta->delta_size = atol(tmp);
return(delta);
}
@@ -265,9 +256,11 @@ pmdelta_t *_alpm_delta_parse(char *line)
void _alpm_delta_free(pmdelta_t *delta)
{
FREE(delta->from);
+ FREE(delta->from_md5);
FREE(delta->to);
- FREE(delta->filename);
- FREE(delta->md5sum);
+ FREE(delta->to_md5);
+ FREE(delta->delta);
+ FREE(delta->delta_md5);
FREE(delta);
}
diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h
index 007e5d45..a2ac5f05 100644
--- a/lib/libalpm/delta.h
+++ b/lib/libalpm/delta.h
@@ -22,11 +22,20 @@
#include "alpm.h"
struct __pmdelta_t {
+ /** filename of the 'before' file */
char *from;
+ /** md5sum of the 'before' file */
+ char *from_md5;
+ /** filename of the 'after' file */
char *to;
- unsigned long size;
- char *filename;
- char *md5sum;
+ /** md5sum of the 'after' file */
+ char *to_md5;
+ /** filename of the delta patch */
+ char *delta;
+ /** md5sum of the delta file */
+ char *delta_md5;
+ /** filesize of the delta file */
+ unsigned long delta_size;
};
unsigned long _alpm_delta_path_size(alpm_list_t *deltas);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index decd52b5..5146a994 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -717,7 +717,6 @@ static int apply_deltas(pmtrans_t *trans, alpm_list_t *patches)
pmpkg_t *pkg;
pmdelta_t *d;
char command[PATH_MAX], fname[PATH_MAX];
- char pkgfilename[PATH_MAX];
pkg = alpm_list_getdata(p);
p = alpm_list_next(p);
@@ -742,26 +741,23 @@ static int apply_deltas(pmtrans_t *trans, alpm_list_t *patches)
/* build the patch command */
snprintf(command, PATH_MAX,
- "xdelta patch" /* the command */
- " %s/%s" /* the delta */
- " %s/%s-%s-%s" PKGEXT /* the 'from' package */
- " %s/%s-%s-%s" PKGEXT, /* the 'to' package */
- cachedir, d->filename,
- cachedir, pkg->name, d->from, pkg->arch,
- cachedir, pkg->name, d->to, pkg->arch);
+ "xdelta patch" /* the command */
+ " %s/%s" /* the delta */
+ " %s/%s" /* the 'from' package */
+ " %s/%s", /* the 'to' package */
+ cachedir, d->delta,
+ cachedir, d->from,
+ cachedir, d->to);
_alpm_log(PM_LOG_DEBUG, _("command: %s\n"), command);
- snprintf(pkgfilename, PATH_MAX, "%s-%s-%s" PKGEXT,
- pkg->name, d->to, pkg->arch);
-
- EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_START, pkgfilename, d->filename);
+ EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_START, d->to, d->delta);
if(system(command) == 0) {
EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_DONE, NULL, NULL);
/* delete the delta file */
- snprintf(fname, PATH_MAX, "%s/%s", cachedir, d->filename);
+ snprintf(fname, PATH_MAX, "%s/%s", cachedir, d->delta);
unlink(fname);
/* Delete the 'from' package but only if it is an intermediate
@@ -769,8 +765,7 @@ static int apply_deltas(pmtrans_t *trans, alpm_list_t *patches)
* as if deltas were not used. Delete the package file if the
* previous iteration of the loop used the same package. */
if(pkg == lastpkg) {
- snprintf(fname, PATH_MAX, "%s/%s-%s-%s" PKGEXT,
- cachedir, pkg->name, d->from, pkg->arch);
+ snprintf(fname, PATH_MAX, "%s/%s", cachedir, d->from);
unlink(fname);
} else {
lastpkg = pkg;
@@ -864,12 +859,12 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
for(dlts = delta_path; dlts; dlts = alpm_list_next(dlts)) {
pmdelta_t *d = (pmdelta_t *)alpm_list_getdata(dlts);
- char *fpath2 = _alpm_filecache_find(d->filename);
+ char *fpath2 = _alpm_filecache_find(d->delta);
if(!fpath2) {
/* add the delta filename to the download list if
- * it's not in the cache*/
- files = alpm_list_add(files, strdup(d->filename));
+ * it's not in the cache */
+ files = alpm_list_add(files, strdup(d->delta));
}
/* save the package and delta so that the xdelta patch