Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
predict disk space requirement and size necessary to download
Baptiste Daroussin committed 15 years ago
commit 6fabac894c00820edaf3ddaf90f5c6ae9bc717b7
parent 88716c91a0bf2f771ff3129773623602e8fc5d01
5 files changed +106 -4
modified libpkg/pkg.c
@@ -105,6 +105,28 @@ pkg_flatsize(struct pkg *pkg)
	return (pkg->flatsize);
}

+
int64_t
+
pkg_new_flatsize(struct pkg *pkg)
+
{
+
	if (pkg == NULL) {
+
		ERROR_BAD_ARG("pkg");
+
		return (-1);
+
	}
+

+
	return (pkg->new_flatsize);
+
}
+

+
int64_t
+
pkg_new_pkgsize(struct pkg *pkg)
+
{
+
	if (pkg == NULL) {
+
		ERROR_BAD_ARG("pkg");
+
		return (-1);
+
	}
+

+
	return (pkg->new_pkgsize);
+
}
+

struct pkg_script **
pkg_scripts(struct pkg *pkg)
{
@@ -380,6 +402,8 @@ pkg_reset(struct pkg *pkg)
		sbuf_reset(pkg->fields[i].value);

	pkg->flatsize = 0;
+
	pkg->new_flatsize = 0;
+
	pkg->new_pkgsize = 0;
	pkg->flags = 0;
	pkg->rowid = 0;

@@ -433,6 +457,34 @@ pkg_setflatsize(struct pkg *pkg, int64_t size)
}

int
+
pkg_setnewflatsize(struct pkg *pkg, int64_t size)
+
{
+
	if (pkg == NULL)
+
		return (ERROR_BAD_ARG("pkg"));
+

+
	if (size <0)
+
		return (ERROR_BAD_ARG("size"));
+

+
	pkg->new_flatsize = size;
+

+
	return (EPKG_OK);
+
}
+

+
int
+
pkg_setnewpkgsize(struct pkg *pkg, int64_t size)
+
{
+
	if (pkg == NULL)
+
		return (ERROR_BAD_ARG("pkg"));
+

+
	if (size <0)
+
		return (ERROR_BAD_ARG("size"));
+

+
	pkg->new_pkgsize = size;
+

+
	return (EPKG_OK);
+
}
+

+
int
pkg_addscript(struct pkg *pkg, const char *path)
{
	struct pkg_script *script;
modified libpkg/pkg.h
@@ -86,7 +86,8 @@ typedef enum {
	PKG_MAINTAINER,
	PKG_WWW,
	PKG_PREFIX,
-
	PKG_NEWVERSION
+
	PKG_NEWVERSION,
+
	PKG_NEWPATH
} pkg_attr;

/**
@@ -192,6 +193,16 @@ const char *pkg_get(struct pkg const * const , const pkg_attr);
int64_t pkg_flatsize(struct pkg *);

/**
+
 * @return the size of the uncompressed package, in its futur version.
+
 */
+
int64_t pkg_new_flatsize(struct pkg *);
+

+
/**
+
 * @return the size of the compressed package, in its futur version.
+
 */
+
int64_t pkg_new_pkgsize(struct pkg *);
+

+
/**
 * @return NULL-terminated array of pkg.
 */
struct pkg ** pkg_deps(struct pkg *);
@@ -258,6 +269,20 @@ int pkg_set_from_file(struct pkg *pkg, pkg_attr attr, const char *file);
int pkg_setflatsize(struct pkg *pkg, int64_t size);

/**
+
 * Set the uncompressed size of the package, in its futur version.
+
 * @return An error code.
+
 */
+
int pkg_setnewflatsize(struct pkg *pkg, int64_t size);
+

+
/**
+
 * Set the compressed size of the package, in its futur version.
+
 * @return An error code.
+
 */
+
int pkg_setnewpkgsize(struct pkg *pkg, int64_t size);
+

+

+

+
/**
 * Allocate a new struct pkg and add it to the deps of pkg.
 * @return An error code.
 */
modified libpkg/pkg_private.h
@@ -9,7 +9,7 @@

#include "pkg_util.h"

-
#define PKG_NUM_FIELDS 13
+
#define PKG_NUM_FIELDS 14

struct pkg {
	struct {
@@ -17,6 +17,8 @@ struct pkg {
		unsigned int optional :1;
	} fields[PKG_NUM_FIELDS];
	int64_t flatsize;
+
	int64_t new_flatsize;
+
	int64_t new_pkgsize;
	struct array deps;
	struct array rdeps;
	struct array conflicts;
modified libpkg/pkgdb.c
@@ -333,8 +333,12 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
			if ((ret = pkgdb_loadmtree(it->db, pkg)) != EPKG_OK)
				return (ret);

-
		if (flags & PKG_LOAD_NEWVERSION)
+
		if (flags & PKG_LOAD_NEWVERSION) {
			pkg_set(pkg, PKG_NEWVERSION, sqlite3_column_text(it->stmt, 13));
+
			pkg_setnewflatsize(pkg, sqlite3_column_int64(it->stmt, 14));
+
			pkg_setnewpkgsize(pkg, sqlite3_column_int64(it->stmt, 15));
+
			pkg_set(pkg, PKG_NEWPATH, sqlite3_column_text(it->stmt, 16));
+
		}

		return (EPKG_OK);
	case SQLITE_DONE:
@@ -1216,7 +1220,7 @@ pkgdb_repos_diff(struct pkgdb *db)
	const char sql[] = ""
		"SELECT l.id, l.origin, l.name, l.version, l.comment, l.desc, "
		"l.message, l.arch, l.osversion, l.maintainer, "
-
		"l.www, l.prefix, l.flatsize, r.version, r.flatsize "
+
		"l.www, l.prefix, l.flatsize, r.version, r.flatsize, r.pkgsize, r.path "
		"FROM main.packages AS l, "
		"remote.packages AS r "
		"WHERE l.origin = r.origin "
modified pkg/upgrade.c
@@ -30,6 +30,9 @@ exec_upgrade(int argc, char **argv)
	struct pkg *pkg = NULL;
	char *packagesite = NULL;
	int retcode = 0;
+
	int64_t oldsize = 0, newsize = 0;
+
	int64_t dlsize = 0;
+
	char size[7];
	properties conf;

	(void) argv;
@@ -72,6 +75,9 @@ exec_upgrade(int argc, char **argv)
	}

	while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_NEWVERSION)) == EPKG_OK) {
+
		oldsize += pkg_flatsize(pkg);
+
		newsize += pkg_new_flatsize(pkg);
+
		dlsize += pkg_new_pkgsize(pkg);
		switch (pkg_version_cmp(pkg_get(pkg, PKG_VERSION), pkg_get(pkg, PKG_NEWVERSION))) {
			case -1:
				printf("%s: upgrade from %s to %s\n", pkg_get(pkg, PKG_NAME),
@@ -83,6 +89,19 @@ exec_upgrade(int argc, char **argv)
				break;
		}
	}
+
	printf("\n");
+

+
	if (oldsize > newsize) {
+
		newsize *= -1;
+
		humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
+
		printf("the upgrade will save %s\n", size);
+
	} else {
+
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
+
		printf("the upgrade will require %s more space\n", size, newsize, oldsize);
+
	}
+
	humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
+
	printf("%s to be downloaded\n", size);
+


	cleanup: