lib/package_unpack.c: compute unpack cb stats only once.

This commit is contained in:
Juan RP
2013-11-15 10:36:31 +01:00
parent e03d49f6bf
commit 44533f9f57

View File

@ -171,7 +171,7 @@ unpack_archive(struct xbps_handle *xhp,
char *pkgname, *dname, *buf, *buf2, *p, *p2; char *pkgname, *dname, *buf, *buf2, *p, *p2;
int ar_rv, rv, entry_type, flags; int ar_rv, rv, entry_type, flags;
bool preserve, update, conf_file, file_exists, skip_obsoletes; bool preserve, update, conf_file, file_exists, skip_obsoletes;
bool softreplace, skip_extract, force, metafile; bool softreplace, skip_extract, force, metafile, xucd_stats;
uid_t euid; uid_t euid;
assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY); assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY);
@ -179,7 +179,7 @@ unpack_archive(struct xbps_handle *xhp,
propsd = filesd = old_filesd = NULL; propsd = filesd = old_filesd = NULL;
force = preserve = update = conf_file = file_exists = false; force = preserve = update = conf_file = file_exists = false;
skip_obsoletes = softreplace = metafile = false; skip_obsoletes = softreplace = metafile = xucd_stats = false;
xbps_dictionary_get_bool(pkg_repod, "preserve", &preserve); xbps_dictionary_get_bool(pkg_repod, "preserve", &preserve);
xbps_dictionary_get_bool(pkg_repod, "skip-obsoletes", &skip_obsoletes); xbps_dictionary_get_bool(pkg_repod, "skip-obsoletes", &skip_obsoletes);
@ -255,7 +255,6 @@ unpack_archive(struct xbps_handle *xhp,
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
rv = xbps_pkg_exec_buffer(xhp, instbuf, instbufsiz, rv = xbps_pkg_exec_buffer(xhp, instbuf, instbufsiz,
pkgver, "pre", update); pkgver, "pre", update);
if (rv != 0) { if (rv != 0) {
@ -296,23 +295,6 @@ unpack_archive(struct xbps_handle *xhp,
} }
continue; continue;
} }
/*
* XXX: duplicate code.
* Create the metaplist file before unpacking any real file.
*/
if (propsd && filesd && !metafile) {
rv = create_pkg_metaplist(xhp, pkgname, pkgver,
propsd, filesd, instbuf, instbufsiz,
rembuf, rembufsiz);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgver,
"%s: [unpack] failed to create metaplist file: %s",
pkgver, strerror(rv));
goto out;
}
metafile = true;
}
/* /*
* If XBPS_PKGFILES or XBPS_PKGPROPS weren't found * If XBPS_PKGFILES or XBPS_PKGPROPS weren't found
* in the archive at this phase, skip all data. * in the archive at this phase, skip all data.
@ -336,6 +318,23 @@ unpack_archive(struct xbps_handle *xhp,
entry_idx++; entry_idx++;
continue; continue;
} }
/*
* XXX: duplicate code.
* Create the metaplist file before unpacking any real file.
*/
if (!metafile) {
rv = create_pkg_metaplist(xhp, pkgname, pkgver,
propsd, filesd, instbuf, instbufsiz,
rembuf, rembufsiz);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgver,
"%s: [unpack] failed to create metaplist file: %s",
pkgver, strerror(rv));
goto out;
}
metafile = true;
}
/* /*
* Prepare unpack callback ops. * Prepare unpack callback ops.
*/ */
@ -345,13 +344,11 @@ unpack_archive(struct xbps_handle *xhp,
xucd.entry = entry_pname; xucd.entry = entry_pname;
xucd.entry_size = entry_size; xucd.entry_size = entry_size;
xucd.entry_is_conf = false; xucd.entry_is_conf = false;
}
/* /*
* Compute total entries in progress data, if set. * Compute total entries in progress data, if set.
* total_entries = files + conf_files + links. * total_entries = files + conf_files + links.
*/ */
if (xhp->unpack_cb != NULL) { if (filesd && !xucd_stats) {
xucd.entry_total_count = 0;
array = xbps_dictionary_get(filesd, "files"); array = xbps_dictionary_get(filesd, "files");
xucd.entry_total_count += xucd.entry_total_count +=
(ssize_t)xbps_array_count(array); (ssize_t)xbps_array_count(array);
@ -361,6 +358,8 @@ unpack_archive(struct xbps_handle *xhp,
array = xbps_dictionary_get(filesd, "links"); array = xbps_dictionary_get(filesd, "links");
xucd.entry_total_count += xucd.entry_total_count +=
(ssize_t)xbps_array_count(array); (ssize_t)xbps_array_count(array);
xucd_stats = true;
}
} }
/* /*
* Always check that extracted file exists and hash * Always check that extracted file exists and hash