Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Speeds up upgrades by using hashtable to detect files/dirs that should be kept
Baptiste Daroussin committed 13 years ago
commit bda157aa3e8d44d14d3f5d2bacfeea0940e64f36
parent 5febf55
4 files changed +33 -22
modified libpkg/pkg.c
@@ -1150,3 +1150,23 @@ pkg_is_installed(struct pkgdb *db, const char *origin)

	return (ret);
}
+

+
bool
+
pkg_has_dir(struct pkg *p, const char *path)
+
{
+
	struct pkg_file *f;
+

+
	HASH_FIND_STR(p->files, __DECONST(char *, path), f);
+

+
	return (f != NULL ? true : false);
+
}
+

+
bool
+
pkg_has_file(struct pkg *p, const char *path)
+
{
+
	struct pkg_dir *d;
+

+
	HASH_FIND_STR(p->dirs, __DECONST(char *, path), d);
+

+
	return (d != NULL ? true : false);
+
}
modified libpkg/pkg.h
@@ -665,6 +665,8 @@ const char *pkg_file_uname(struct pkg_file const * const);
const char *pkg_file_gname(struct pkg_file const * const);
mode_t pkg_file_mode(struct pkg_file const * const);

+
bool pkg_has_dir(struct pkg *, const char *);
+
bool pkg_has_file(struct pkg *, const char *);
/* pkg_dir */
const char *pkg_dir_path(struct pkg_dir const * const);
const char *pkg_dir_uname(struct pkg_dir const * const);
modified libpkg/pkg_jobs.c
@@ -126,32 +126,21 @@ pkg_jobs(struct pkg_jobs *j, struct pkg **pkg)
static int
pkg_jobs_keep_files_to_del(struct pkg *p1, struct pkg *p2)
{
-
	struct pkg_file *f1 = NULL, *f2 = NULL;
-
	struct pkg_dir *d1 = NULL, *d2 = NULL;
+
	struct pkg_file *f = NULL;
+
	struct pkg_dir *d = NULL;

-
	while (pkg_files(p1, &f1) == EPKG_OK) {
-
		if (f1->keep == 1)
+
	while (pkg_files(p1, &f) == EPKG_OK) {
+
		if (f->keep)
			continue;

-
		f2 = NULL;
-
		while (pkg_files(p2, &f2) == EPKG_OK) {
-
			if (strcmp(pkg_file_path(f1), pkg_file_path(f2)) == 0) {
-
				f1->keep = 1;
-
				break;
-
			}
-
		}
+
		f->keep = pkg_has_file(p2, pkg_file_path(f));
	}

-
	while (pkg_dirs(p1, &d1) == EPKG_OK) {
-
		if (d1->keep == 1)
+
	while (pkg_dirs(p1, &d) == EPKG_OK) {
+
		if (d->keep)
			continue;
-
		d2 = NULL;
-
		while (pkg_dirs(p2, &d2) == EPKG_OK) {
-
			if (strcmp(pkg_dir_path(d1), pkg_dir_path(d2)) == 0) {
-
				d1->keep = 1;
-
				break;
-
			}
-
		}
+

+
		d->keep = pkg_has_file(p2, pkg_dir_path(d));
	}

	return (EPKG_OK);
modified libpkg/private/pkg.h
@@ -125,7 +125,7 @@ struct pkg_file {
	char		 sum[SHA256_DIGEST_LENGTH * 2 +1];
	char		 uname[MAXLOGNAME +1];
	char		 gname[MAXLOGNAME +1];
-
	int		 keep;
+
	bool		 keep;
	mode_t		 perm;
	UT_hash_handle	 hh;
};
@@ -135,7 +135,7 @@ struct pkg_dir {
	char		 uname[MAXLOGNAME +1];
	char		 gname[MAXLOGNAME +1];
	mode_t		 perm;
-
	int		 keep;
+
	bool		 keep;
	bool		 try;
	UT_hash_handle	 hh;
};