version 1.32, 2007/07/26 11:30:56 |
version 1.33, 2007/08/08 22:33:39 |
Line 179 pkg_do(char *pkg) |
|
Line 179 pkg_do(char *pkg) |
|
(void) snprintf(log_dir, sizeof(log_dir), "%s/%s", |
(void) snprintf(log_dir, sizeof(log_dir), "%s/%s", |
_pkgdb_getPKGDB_DIR(), pkg); |
_pkgdb_getPKGDB_DIR(), pkg); |
if (!fexists(log_dir) || !(isdir(log_dir) || islinktodir(log_dir))) { |
if (!fexists(log_dir) || !(isdir(log_dir) || islinktodir(log_dir))) { |
{ |
switch (add_installed_pkgs_by_basename(pkg, &pkgs)) { |
/* Check if the given package name matches |
case 1: |
* something with 'pkg-[0-9]*' */ |
return 0; |
char try[MaxPathSize]; |
case 0: |
snprintf(try, MaxPathSize, "%s-[0-9]*", pkg); |
/* No match */ |
if (findmatchingname(_pkgdb_getPKGDB_DIR(), try, |
warnx("can't find package `%s'", pkg); |
add_to_list_fn, &pkgs) > 0) { |
return 1; |
return 0; /* we've just appended some names to the pkgs list, |
case -1: |
* they will be processed after this package. */ |
errx(EXIT_FAILURE, "Error during search in pkgdb for %s", pkg); |
} |
|
} |
} |
|
|
/* No match */ |
|
warnx("can't find package `%s'", pkg); |
|
return 1; |
|
} |
} |
if (chdir(log_dir) == FAIL) { |
if (chdir(log_dir) == FAIL) { |
warnx("can't change directory to '%s'!", log_dir); |
warnx("can't change directory to '%s'!", log_dir); |
|
|
} |
} |
|
|
/* |
/* |
* Function to be called for pkgs found |
* Check if a package "pkgspec" (which can be a pattern) is installed. |
|
* dbdir contains the return value of _pkgdb_getPKGDB_DIR(), for reading only. |
|
* Return 0 if found, 1 otherwise (indicating an error). |
*/ |
*/ |
static int |
static int |
foundpkg(const char *pattern, const char *found, void *vp) |
CheckForPkg(const char *pkgname) |
{ |
{ |
char *data = vp; |
char *best_installed; |
char buf[MaxPathSize+1]; |
|
|
|
/* we only want to display this if it really is a directory */ |
best_installed = find_best_matching_installed_pkg(pkgname); |
snprintf(buf, sizeof(buf), "%s/%s", data, found); |
if (best_installed == NULL && !ispkgpattern(pkgname)) { |
if (!(isdir(buf) || islinktodir(buf))) { |
char *pattern; |
/* return value seems to be ignored for now */ |
|
return -1; |
|
} |
|
|
|
if (!Quiet) { |
if (asprintf(&pattern, "%s-[0-9]*", pkgname) == -1) |
printf("%s\n", found); |
errx(EXIT_FAILURE, "asprintf failed"); |
|
|
|
pkgname = find_best_matching_installed_pkg(pattern); |
|
free(pattern); |
} |
} |
|
|
return 0; |
if (best_installed == NULL) |
} |
return 1; |
|
|
/* |
if (!Quiet) |
* Check if a package "pkgspec" (which can be a pattern) is installed. |
printf("%s\n", best_installed); |
* dbdir contains the return value of _pkgdb_getPKGDB_DIR(), for reading only. |
|
* Return 0 if found, 1 otherwise (indicating an error). |
|
*/ |
|
static int |
|
CheckForPkg(char *pkgspec, char *dbdir) |
|
{ |
|
char buf[MaxPathSize]; |
|
int error; |
|
|
|
if (strpbrk(pkgspec, "<>[]?*{")) { |
free(best_installed); |
/* expensive (pattern) match */ |
return 0; |
error = findmatchingname(dbdir, pkgspec, foundpkg, dbdir); |
|
if (error == -1) |
|
return 1; |
|
else |
|
return !error; |
|
} |
|
/* simple match */ |
|
(void) snprintf(buf, sizeof(buf), "%s/%s", dbdir, pkgspec); |
|
error = !(isdir(buf) || islinktodir(buf)); |
|
if (!error && !Quiet) { |
|
printf("%s\n", pkgspec); |
|
} |
|
if (error) { |
|
/* found nothing - try 'pkg-[0-9]*' */ |
|
|
|
char try[MaxPathSize]; |
|
snprintf(try, MaxPathSize, "%s-[0-9]*", pkgspec); |
|
if (findmatchingname(dbdir, try, foundpkg, dbdir) > 0) { |
|
error = 0; |
|
} |
|
} |
|
return error; |
|
} |
} |
|
|
void |
void |
Line 404 pkg_perform(lpkg_head_t *pkghead) |
|
Line 370 pkg_perform(lpkg_head_t *pkghead) |
|
|
|
/* Overriding action? */ |
/* Overriding action? */ |
if (CheckPkg) { |
if (CheckPkg) { |
err_cnt += CheckForPkg(CheckPkg, dbdir); |
err_cnt += CheckForPkg(CheckPkg); |
} else if (Which != WHICH_LIST) { |
} else if (Which != WHICH_LIST) { |
if (!(isdir(dbdir) || islinktodir(dbdir))) |
if (!(isdir(dbdir) || islinktodir(dbdir))) |
return 1; |
return 1; |