summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2008-03-09 20:55:25 +0000
committerjoerg <joerg@pkgsrc.org>2008-03-09 20:55:25 +0000
commitc0e008f2f1627cd50deb9bea72700a64c4bb4fe8 (patch)
treeff621c0d0adb6b50ca1519681eb4ec024e539a0c
parent849d11cabb61feaa8f667ec07d3bfc507720f918 (diff)
downloadpkgsrc-c0e008f2f1627cd50deb9bea72700a64c4bb4fe8.tar.gz
Stop chdir/getcwd/fchdir dance in lsall and lsbest, just use the passed
in path name. This is more consistent when symbolic links are involved as it doesn't do the equivalent of realpath(3) for the path any longer.
-rw-r--r--pkgtools/pkg_install/files/admin/main.c49
1 files changed, 7 insertions, 42 deletions
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c
index 57b333a48cd..475f49c1acb 100644
--- a/pkgtools/pkg_install/files/admin/main.c
+++ b/pkgtools/pkg_install/files/admin/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.36 2008/03/09 20:36:22 joerg Exp $ */
+/* $NetBSD: main.c,v 1.37 2008/03/09 20:55:25 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.36 2008/03/09 20:36:22 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.37 2008/03/09 20:55:25 joerg Exp $");
#endif
/*-
@@ -439,86 +439,51 @@ main(int argc, char *argv[])
}
} else if (strcasecmp(argv[0], "lsall") == 0) {
- int saved_wd;
-
argv++; /* "lsall" */
- /* preserve cwd */
- saved_wd=open(".", O_RDONLY);
- if (saved_wd == -1)
- err(EXIT_FAILURE, "Cannot save working dir");
-
while (*argv != NULL) {
/* args specified */
int rc;
const char *basep, *dir;
- char cwd[MaxPathSize];
dir = lsdirp ? lsdirp : dirname_of(*argv);
basep = basename_of(*argv);
- fchdir(saved_wd);
- rc = chdir(dir);
- if (rc == -1)
- err(EXIT_FAILURE, "Cannot chdir to %s", dir);
-
- if (getcwd(cwd, sizeof(cwd)) == NULL)
- err(EXIT_FAILURE, "getcwd");
-
if (show_basename_only)
- rc = match_local_files(cwd, use_default_sfx, 1, basep, lsbasepattern, NULL);
+ rc = match_local_files(dir, use_default_sfx, 1, basep, lsbasepattern, NULL);
else
- rc = match_local_files(cwd, use_default_sfx, 1, basep, lspattern, cwd);
+ rc = match_local_files(dir, use_default_sfx, 1, basep, lspattern, (void *)dir);
if (rc == -1)
errx(EXIT_FAILURE, "Error from match_local_files(\"%s\", \"%s\", ...)",
- cwd, basep);
+ dir, basep);
argv++;
}
- close(saved_wd);
-
} else if (strcasecmp(argv[0], "lsbest") == 0) {
- int saved_wd;
-
argv++; /* "lsbest" */
- /* preserve cwd */
- saved_wd=open(".", O_RDONLY);
- if (saved_wd == -1)
- err(EXIT_FAILURE, "Cannot save working dir");
-
while (*argv != NULL) {
/* args specified */
const char *basep, *dir;
- char cwd[MaxPathSize];
char *p;
dir = lsdirp ? lsdirp : dirname_of(*argv);
basep = basename_of(*argv);
- fchdir(saved_wd);
- if (chdir(dir) == -1)
- err(EXIT_FAILURE, "Cannot chdir to %s", dir);
-
- if (getcwd(cwd, sizeof(cwd)) == NULL)
- err(EXIT_FAILURE, "getcwd");
-
- p = find_best_matching_file(cwd, basep, use_default_sfx, 1);
+ p = find_best_matching_file(dir, basep, use_default_sfx, 1);
if (p) {
if (show_basename_only)
printf("%s\n", p);
else
- printf("%s/%s\n", cwd, p);
+ printf("%s/%s\n", dir, p);
free(p);
}
argv++;
}
- close(saved_wd);
-
} else if (strcasecmp(argv[0], "list") == 0 ||
strcasecmp(argv[0], "dump") == 0) {