summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2000-09-18 07:41:48 +0000
committersobomax <sobomax@FreeBSD.org>2000-09-18 07:41:48 +0000
commitfbb730aa4fed9f43a7663507196c62a2c979c032 (patch)
tree0cd16f021627e993056e475511f41eac720fe628 /usr.sbin/pkg_install/lib
parent91f91457a7cc308612accc12b3d87ddeb05c41bf (diff)
downloadFreeBSD-src-fbb730aa4fed9f43a7663507196c62a2c979c032.zip
FreeBSD-src-fbb730aa4fed9f43a7663507196c62a2c979c032.tar.gz
Fix symlink-to-a-dir handling in pkg_delete.
Reviewed by: -ports Tested by: bento
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/file.c25
-rw-r--r--usr.sbin/pkg_install/lib/lib.h1
-rw-r--r--usr.sbin/pkg_install/lib/plist.c4
3 files changed, 24 insertions, 6 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index 49db198..a54df9e 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -40,7 +40,7 @@ fexists(char *fname)
return FALSE;
}
-/* Quick check to see if something is a directory */
+/* Quick check to see if something is a directory or symlink to a directory */
Boolean
isdir(char *fname)
{
@@ -54,7 +54,7 @@ isdir(char *fname)
return FALSE;
}
-/* Check to see if file is a dir, and is empty */
+/* Check to see if file is a dir or symlink to a dir, and is empty */
Boolean
isemptydir(char *fname)
{
@@ -77,6 +77,10 @@ isemptydir(char *fname)
return FALSE;
}
+/*
+ * Returns TRUE if file is a regular file or symlink pointing to a regular
+ * file
+ */
Boolean
isfile(char *fname)
{
@@ -86,8 +90,11 @@ isfile(char *fname)
return FALSE;
}
-/* Check to see if file is a file and is empty. If nonexistent or not
- a file, say "it's empty", otherwise return TRUE if zero sized. */
+/*
+ * Check to see if file is a file or symlink pointing to a file and is empty.
+ * If nonexistent or not a file, say "it's empty", otherwise return TRUE if
+ * zero sized.
+ */
Boolean
isemptyfile(char *fname)
{
@@ -99,6 +106,16 @@ isemptyfile(char *fname)
return TRUE;
}
+/* Returns TRUE if file is a symbolic link. */
+Boolean
+issymlink(char *fname)
+{
+ struct stat sb;
+ if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode))
+ return TRUE;
+ return FALSE;
+}
+
/* Returns TRUE if file is a URL specification */
Boolean
isURL(char *fname)
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index 3d5f0ec..2584655 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -129,6 +129,7 @@ Boolean isemptydir(char *fname);
Boolean isemptyfile(char *fname);
Boolean isfile(char *);
Boolean isempty(char *);
+Boolean issymlink(char *);
Boolean isURL(char *);
char *fileGetURL(char *, char *);
char *fileFindByPath(char *, char *);
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 6dfbabc..88f6876 100644
--- a/usr.sbin/pkg_install/lib/plist.c
+++ b/usr.sbin/pkg_install/lib/plist.c
@@ -390,7 +390,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
case PLIST_FILE:
last_file = p->name;
sprintf(tmp, "%s/%s", Where, p->name);
- if (isdir(tmp) && fexists(tmp)) {
+ if (isdir(tmp) && fexists(tmp) && !issymlink(tmp)) {
warnx("cannot delete specified file `%s' - it is a directory!\n"
"this packing list is incorrect - ignoring delete request", tmp);
}
@@ -477,7 +477,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
return 1;
}
- else if (isdir(dir)) {
+ else if (isdir(dir) && !issymlink(dir)) {
if (RMDIR(dir) && !ign_err)
return 1;
}
OpenPOWER on IntegriCloud