PERFORCE change 129785 for review
Garrett Cooper
gcooper at FreeBSD.org
Thu Nov 29 11:25:13 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=129785
Change 129785 by gcooper at shiina-ibook on 2007/11/29 19:24:47
- Add force functionality to pkg_db and all related function prototypes.
- Style and logic consolidation.
Affected files ...
.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db.c#3 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db.h#2 edit
.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_freebsd.c#5 edit
Differences ...
==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db.c#3 (text+ko) ====
@@ -63,7 +63,7 @@
struct stat sb;
db = malloc(sizeof(struct pkg_db));
- if (!db)
+ if (db == NULL)
return NULL;
/* Make a relative path into an absolute path */
@@ -79,7 +79,7 @@
db->db_base = strdup(base);
}
- if (!db->db_base) {
+ if (db->db_base == NULL) {
free(db);
return NULL;
}
@@ -88,7 +88,7 @@
if (stat(db->db_base, &sb) == -1) {
pkg_db_free(db);
return NULL;
- } else if (!S_ISDIR(sb.st_mode)) {
+ } else if (S_ISDIR(sb.st_mode) == 0) {
pkg_db_free(db);
return NULL;
}
@@ -128,7 +128,7 @@
*
* These are the functions to talk to a package database.
* The database is created by a system dependent constructor.
- * eg. pkg_db_open_freebsd() on FreeBSD systems
+ * e.g. pkg_db_open_freebsd() on FreeBSD systems
*
* @{
*/
@@ -142,13 +142,16 @@
* @param scripts If true run the package's scripts
* @param fake If true we will only fetch the package and report what would
* have happened during the install
+ * @param force Force the install operation to go through (or at
+ * least force it to go through if the preinstall script fails..).
* @param action A callback that is used to inform the user the status
* of the installation
* @return 0 if the package is installed, -1 otherwise
*/
int
pkg_db_install_pkg_action(struct pkg_db *db, struct pkg *pkg,
- const char *prefix, int reg, int scripts, int fake, pkg_db_action *action)
+ const char *prefix, int reg, int scripts, int fake, int force,
+ pkg_db_action *action)
{
if (db == NULL)
return -1;
@@ -221,13 +224,13 @@
pkg_db_get_installed_match_count(struct pkg_db *db, pkg_db_match *match,
unsigned int count, const void *data)
{
- if (!db)
+ if (db == NULL)
return NULL;
if (match == NULL)
match = pkg_match_all;
- if (db->pkg_get_installed_match)
+ if (db->pkg_get_installed_match != NULL)
return db->pkg_get_installed_match(db, match, count, data);
return NULL;
@@ -240,10 +243,7 @@
struct pkg *
pkg_db_get_package(struct pkg_db *db, const char *pkg_name)
{
- if (!db || !pkg_name)
- return NULL;
-
- if (db->pkg_get_package)
+ if (db != NULL && pkg_name != NULL && db->pkg_get_package)
return db->pkg_get_package(db, pkg_name);
return NULL;
@@ -266,15 +266,11 @@
pkg_db_delete_package_action(struct pkg_db *db, struct pkg *pkg, int scripts,
int fake, int force, int clean_dirs, pkg_db_action *action)
{
- if (db == NULL || pkg == NULL)
- return -1;
-
- if (action == NULL)
- return -1;
-
- if (db->pkg_deinstall != NULL)
+ if (db != NULL && pkg != NULL && action != NULL &&
+ db->pkg_deinstall != NULL) {
return db->pkg_deinstall(db, pkg, scripts, fake, force,
clean_dirs, action);
+ }
return -1;
}
==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db.h#2 (text+ko) ====
@@ -28,6 +28,9 @@
#ifndef __LIBPKG_PKG_DB_H__
#define __LIBPKG_PKG_DB_H__
+
+#define PKGDB_DEPS_READAHEAD_SIZE 1024
+
/*
* A place to install packages to and uninstall packages from
*/
@@ -49,7 +52,7 @@
struct pkg_db *pkg_db_open_freebsd(const char *);
int pkg_db_install_pkg_action(struct pkg_db *, struct pkg *,
- const char *, int, int, int, pkg_db_action *);
+ const char *, int, int, int, int, pkg_db_action *);
int pkg_db_is_installed(struct pkg_db *, struct pkg *);
struct pkg **pkg_db_get_installed(struct pkg_db *);
struct pkg **pkg_db_get_installed_match(struct pkg_db *, pkg_db_match *,
==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_freebsd.c#5 (text+ko) ====
@@ -176,15 +176,17 @@
* specified by the pkg_script_pre and pkg_script_post variables.
* @param fake Should we actually install the package or
* just report what would have happened
+ * @param force Force the install operation to go through (or at
+ * least force it to go through if the preinstall script fails..).
* @param pkg_action A function to call when an action takes place
- * @bug When the install fails part way through remove some files are left.
+ * @bug When the install fails part way through some files are left.
* Remove these.
* @return 0 on success, -1 on error
*/
static int
freebsd_install_pkg_action(struct pkg_db *db, struct pkg *pkg,
const char *prefix, int reg, int exec_pkg_scripts, int fake,
- pkg_db_action *pkg_action)
+ int force, pkg_db_action *pkg_action)
{
struct pkg_install_data install_data;
char cwd[MAXPATHLEN];
@@ -209,11 +211,12 @@
pkg_action(PKG_DB_PACKAGE, "Package name is %s", pkg_get_name(pkg));
/* Run +REQUIRE */
- pkg_action(PKG_DB_INFO, "Running ... for %s..", pkg_get_name(pkg));
+ pkg_action(PKG_DB_INFO, "Running requirements... for %s..",
+ pkg_get_name(pkg));
if (fake == 0) {
- /** @todo Check if the force flag is set */
- if (pkg_run_script(pkg, prefix, pkg_script_require) != 0) {
+ if (pkg_run_script(pkg, prefix, pkg_script_require) != 0 &&
+ force == 0) {
chdir(cwd);
return -1;
}
@@ -254,12 +257,7 @@
pkg_run_script(pkg, prefix, pkg_script_post);
/*
- * Andrew Turner: @todo Display contents of \@display
- *
- * Garrett Cooper: Looking at the original pkg_install,
- * this doesn't appear to be implemented other than just
- * as a printf statement. What is the purpose of this
- * directive?
+ * @todo Display contents of \@display
*/
chdir(cwd);
@@ -289,15 +287,15 @@
is_installed = -1;
- /* Does the package repo directory exist */
+ /* Does the package repo directory exist? */
if (stat(dir, &sb) == 0 && S_ISDIR(sb.st_mode) != 0) {
- /* The passed package is installed */
+ /* pkg is installed */
free(dir);
return 0;
}
free(dir);
- /* Does the package have an origin and if so is that origin installed */
+ /* Does the package have an origin; if so is that origin installed? */
if (pkg_get_origin(pkg) != NULL) {
pkgs = freebsd_get_installed_match(db, pkg_match_by_origin,
@@ -348,12 +346,13 @@
packages_size = sizeof(char *);
packages = malloc(packages_size);
- if (!packages) {
+ if (packages == NULL) {
closedir(d);
return NULL;
}
packages[0] = NULL;
packages_pos = 0;
+
while((de = readdir(d)) != NULL) {
struct pkg *pkg;
@@ -375,11 +374,12 @@
packages[packages_pos] = NULL;
/* Stop after count packages */
- if (count != 0 && packages_pos == count + 1)
+ if (count != 0 && packages_pos == (count + 1))
break;
- } else
+ } else {
pkg_free(pkg);
+ }
free(dir);
}
closedir(d);
@@ -398,6 +398,7 @@
snprintf(dir, MAXPATHLEN, "%s/var/db/pkg/%s", db->db_base, pkg_name);
pkg_remove_extra_slashes(dir);
return pkg_new_freebsd_installed(pkg_name, dir);
+
}
/**
@@ -433,11 +434,12 @@
deps = pkg_get_reverse_dependencies(real_pkg);
/* No dependencies */
- if (deps == NULL) {
+ if (deps == NULL)
return -1;
- }
+
/* We have dependencies to go through.. */
else if (deps[0] != NULL) {
+
unsigned int pos, buf_size, buf_used;
char *buf;
@@ -446,6 +448,7 @@
buf = (char*) malloc(buf_size);
if (buf == NULL) {
+
pkg_action(PKG_DB_INFO,
"package '%s' is required by other packages and "
"may not be deinstalled.\n"
@@ -453,6 +456,7 @@
"packages (buffer memory could not be allocated)",
pkg_get_name(real_pkg));
return -1;
+
}
/* Load the package names into a buffer */
@@ -476,11 +480,11 @@
"package '%s' is required by these packages and may not be"
" deinstalled%s:\n%s",
pkg_get_name(real_pkg),
- ( force == ? "" : "(but I'll delete it anyway)"), buf);
+ ( force == 0 ? "" : "(but I'll delete it anyway)"), buf);
free(buf);
/* Only return when the not being forced to */
- if (force != 0)
+ if (force == 0)
return -1;
}
@@ -550,19 +554,26 @@
pkg_get_name(real_pkg));
if (deps != NULL) {
unsigned int pos;
+
for (pos = 0; deps[pos] != NULL; pos++) {
+
struct pkgfile *file;
pkg_action(PKG_DB_INFO, "Trying to remove "
"dependency on package '%s' with '%s' origin.",
pkg_get_name(deps[pos]), pkg_get_origin(deps[pos]));
+
if (fake == 0) {
+
file = pkg_get_control_file(deps[pos],
"+REQUIRED_BY");
pkgfile_remove_line(file,
pkg_get_name(real_pkg));
+
}
+
}
+
}
/* Do the deinstall */
@@ -654,12 +665,8 @@
}
pkg_remove_extra_slashes(install_data->directory);
- if (strcmp(dir, ".") == 0) {
- pkg_action(PKG_DB_PACKAGE, "Change working directory to .");
- } else {
- pkg_action(PKG_DB_PACKAGE, "Change working directory to %s",
- install_data->directory);
- }
+ pkg_action(PKG_DB_PACKAGE, "Change working directory to %s",
+ ( strcmp(dir, ".") == 0 ? "." : install_data->directory));
if (install_data->fake == 0) {
pkg_dir_build(install_data->directory, 0);
@@ -691,7 +698,7 @@
pkgfile_get_name(file));
pkg_action(PKG_DB_PACKAGE, "%s", pkgfile_get_name(file));
- if (!install_data->fake)
+ if (install_data->fake == 0)
return pkgfile_write(file);
return 0;
}
@@ -724,9 +731,10 @@
} else {
if (pkgfile_unlink(file) != 0)
return -1;
- if (install_data->empty_dirs)
+ if (install_data->empty_dirs != 0) {
if (pkg_dir_clean(dirname(pkgfile_get_name(file))) != 0)
return -1;
+ }
return 0;
}
}
@@ -753,9 +761,8 @@
install_data->last_file);
pkg_action(PKG_DB_PACKAGE, "Execute '%s'", the_cmd);
- if (!install_data->fake) {
+ if (install_data->fake == 0)
return pkg_exec(the_cmd);
- }
return 0;
}
@@ -794,7 +801,7 @@
pkg_action(PKG_DB_INFO, "Attempting to record package into %s..",
real_dir);
- if (!install_data->fake) {
+ if (install_data->fake == 0) {
pkg_dir_build(real_dir, 0755);
/*
@@ -811,8 +818,8 @@
pkg_freebsd_contents_update_prefix(contents,
prefix);
pkgfile_free(control[pos]);
- control[pos] = pkg_freebsd_contents_get_file(
- contents);
+ control[pos] =
+ pkg_freebsd_contents_get_file(contents);
}
freebsd_install_file(pkg, pkg_action_null, data,
control[pos]);
@@ -878,22 +885,21 @@
assert(control[0] != NULL);
/* Remove the control files */
for (pos = 0; control[pos] != NULL; pos++) {
- if (!install_data->fake) {
+ if (install_data->fake == 0)
pkgfile_unlink(control[pos]);
- }
}
snprintf(db_dir, FILENAME_MAX, "%s" DB_LOCATION "/%s/",
install_data->db->db_base, pkg_get_name(pkg));
pkg_remove_extra_slashes(db_dir);
dir = pkgfile_new_from_disk(db_dir, 0);
+
if (dir == NULL)
return -1;
- if (install_data->fake) {
+ if (install_data->fake == 1)
return 0;
- } else {
- return pkgfile_unlink(dir);
- }
+
+ return pkgfile_unlink(dir);
}
#ifdef DEAD
@@ -906,7 +912,7 @@
int fake)
{
unsigned int i;
- int state;
+ int new_state, state;
assert(db != NULL);
assert(contents != NULL);
@@ -915,17 +921,18 @@
if (contents->lines[0].line_type != PKG_LINE_COMMENT) {
return -1;
- } else if (strcmp(contents->lines[0].data, "PKG_FORMAT_REVISION:1.1")) {
+ } else if (0 != strcmp(contents->lines[0].data,
+ "PKG_FORMAT_REVISION:1.1")) {
return -1;
}
/* Run through a NFA to check the head */
for (i = 0; i < contents->line_count; i++) {
- int new_state = -2;
new_state = pkg_states[state][contents->lines[i].line_type];
- if (new_state == -1) {
+
+ if (new_state == -1)
break;
- }
+
/* If the current line is @chdir... do it */
if (contents->lines[i].line_type == PKG_LINE_CWD) {
if (freebsd_do_cwd(db, NULL, contents->lines[i].data,
@@ -935,9 +942,9 @@
}
state = new_state;
}
- if (state != 4 && state != 6) {
+ if (state != 4 && state != 6)
return -1;
- }
+
return i;
}
#endif
More information about the p4-projects
mailing list