Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/be_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/be_sync.c')
-rw-r--r--lib/libalpm/be_sync.c106
1 files changed, 39 insertions, 67 deletions
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 3c990246..c4673b1b 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -18,10 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <errno.h>
+#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include <unistd.h>
/* libarchive */
@@ -212,6 +212,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
/* print server + filename into a buffer */
len = strlen(server) + strlen(db->treename) + 5;
+ /* TODO fix leak syncpath and umask unset */
MALLOC(payload.fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
snprintf(payload.fileurl, len, "%s/%s.db", server, db->treename);
payload.handle = handle;
@@ -234,6 +235,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
/* if we downloaded a DB, we want the .sig from the same server */
/* print server + filename into a buffer (leave space for .sig) */
len = strlen(server) + strlen(db->treename) + 9;
+ /* TODO fix leak syncpath and umask unset */
MALLOC(payload.fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
snprintf(payload.fileurl, len, "%s/%s.db.sig", server, db->treename);
payload.handle = handle;
@@ -316,7 +318,8 @@ static alpm_pkg_t *load_pkg_for_entry(alpm_db_t *db, const char *entryname,
return NULL;
}
- if(likely_pkg && strcmp(likely_pkg->name, pkgname) == 0) {
+ if(likely_pkg && pkgname_hash == likely_pkg->name_hash
+ && strcmp(likely_pkg->name, pkgname) == 0) {
pkg = likely_pkg;
} else {
pkg = _alpm_pkghash_find(db->pkgcache, pkgname);
@@ -348,61 +351,38 @@ static alpm_pkg_t *load_pkg_for_entry(alpm_db_t *db, const char *entryname,
return pkg;
}
-/*
- * This is the data table used to generate the estimating function below.
- * "Weighted Avg" means averaging the bottom table values; thus each repo, big
- * or small, will have equal influence. "Unweighted Avg" means averaging the
- * sums of the top table columns, thus each package has equal influence. The
- * final values are calculated by (surprise) averaging the averages, because
- * why the hell not.
- *
- * Database Pkgs tar bz2 gz xz
- * community 2096 5294080 256391 421227 301296
- * core 180 460800 25257 36850 29356
- * extra 2606 6635520 294647 470818 339392
- * multilib 126 327680 16120 23261 18732
- * testing 76 204800 10902 14348 12100
- *
- * Bytes Per Package
- * community 2096 2525.80 122.32 200.97 143.75
- * core 180 2560.00 140.32 204.72 163.09
- * extra 2606 2546.25 113.06 180.67 130.23
- * multilib 126 2600.63 127.94 184.61 148.67
- * testing 76 2694.74 143.45 188.79 159.21
-
- * Weighted Avg 2585.48 129.42 191.95 148.99
- * Unweighted Avg 2543.39 118.74 190.16 137.93
- * Average of Avgs 2564.44 124.08 191.06 143.46
- */
+/* This function doesn't work as well as one might think, as size of database
+ * entries varies considerably. Adding signatures nearly doubles the size of a
+ * single entry; deltas also can make for large variations in size. These
+ * current values are heavily influenced by Arch Linux; databases with no
+ * deltas and a single signature per package. */
static size_t estimate_package_count(struct stat *st, struct archive *archive)
{
- unsigned int per_package;
+ int per_package;
switch(archive_compression(archive)) {
case ARCHIVE_COMPRESSION_NONE:
- per_package = 2564;
+ per_package = 3015;
break;
case ARCHIVE_COMPRESSION_GZIP:
- per_package = 191;
+ case ARCHIVE_COMPRESSION_COMPRESS:
+ per_package = 464;
break;
case ARCHIVE_COMPRESSION_BZIP2:
- per_package = 124;
- break;
- case ARCHIVE_COMPRESSION_COMPRESS:
- per_package = 193;
+ per_package = 394;
break;
case ARCHIVE_COMPRESSION_LZMA:
case ARCHIVE_COMPRESSION_XZ:
- per_package = 143;
+ per_package = 400;
break;
#ifdef ARCHIVE_COMPRESSION_UU
case ARCHIVE_COMPRESSION_UU:
- per_package = 3543;
+ per_package = 3015 * 4 / 3;
break;
#endif
default:
/* assume it is at least somewhat compressed */
- per_package = 200;
+ per_package = 500;
}
return (size_t)((st->st_size / per_package) + 1);
}
@@ -411,7 +391,7 @@ static int sync_db_populate(alpm_db_t *db)
{
const char *dbpath;
size_t est_count;
- int count = 0;
+ int count, fd;
struct stat buf;
struct archive *archive;
struct archive_entry *entry;
@@ -423,38 +403,24 @@ static int sync_db_populate(alpm_db_t *db)
if(db->status & DB_STATUS_MISSING) {
RET_ERR(db->handle, ALPM_ERR_DB_NOT_FOUND, -1);
}
-
- if((archive = archive_read_new()) == NULL) {
- RET_ERR(db->handle, ALPM_ERR_LIBARCHIVE, -1);
- }
-
- archive_read_support_compression_all(archive);
- archive_read_support_format_all(archive);
-
dbpath = _alpm_db_path(db);
if(!dbpath) {
/* pm_errno set in _alpm_db_path() */
return -1;
}
- _alpm_log(db->handle, ALPM_LOG_DEBUG, "opening database archive %s\n", dbpath);
-
- if(archive_read_open_filename(archive, dbpath,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- _alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath,
- archive_error_string(archive));
- archive_read_finish(archive);
- RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
- }
- if(stat(dbpath, &buf) != 0) {
- RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
+ fd = _alpm_open_archive(db->handle, dbpath, &buf,
+ &archive, ALPM_ERR_DB_OPEN);
+ if(fd < 0) {
+ return -1;
}
est_count = estimate_package_count(&buf, archive);
- /* initialize hash at 66% full */
- db->pkgcache = _alpm_pkghash_create(est_count * 3 / 2);
+ db->pkgcache = _alpm_pkghash_create(est_count);
if(db->pkgcache == NULL) {
- RET_ERR(db->handle, ALPM_ERR_MEMORY, -1);
+ db->handle->pm_errno = ALPM_ERR_MEMORY;
+ count = -1;
+ goto cleanup;
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
@@ -473,14 +439,19 @@ static int sync_db_populate(alpm_db_t *db)
}
count = alpm_list_count(db->pkgcache->list);
-
if(count > 0) {
- db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp);
+ db->pkgcache->list = alpm_list_msort(db->pkgcache->list,
+ (size_t)count, _alpm_pkg_cmp);
}
- archive_read_finish(archive);
- _alpm_log(db->handle, ALPM_LOG_DEBUG, "added %d packages to package cache for db '%s'\n",
+ _alpm_log(db->handle, ALPM_LOG_DEBUG,
+ "added %d packages to package cache for db '%s'\n",
count, db->treename);
+cleanup:
+ archive_read_finish(archive);
+ if(fd >= 0) {
+ CLOSE(fd);
+ }
return count;
}
@@ -605,7 +576,8 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
while(1) {
READ_NEXT();
if(strlen(line) == 0) break;
- pkg->deltas = alpm_list_add(pkg->deltas, _alpm_delta_parse(line));
+ pkg->deltas = alpm_list_add(pkg->deltas,
+ _alpm_delta_parse(db->handle, line));
}
}
}