Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Aug 2010 19:31:26 GMT
From:      Julien Laffaye <jlaffaye@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 181741 for review
Message-ID:  <201008021931.o72JVQGD035785@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@181741?ac=10

Change 181741 by jlaffaye@jlaffaye-chulak on 2010/08/02 19:31:01

	Replace the make_hierarchy() function by mkdirs().
	The code was inspired by the mkdir(1) utility in our tree.
	Remove apply_perms() and its silly globals.

Affected files ...

.. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/add.h#6 edit
.. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#13 edit
.. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/futil.c#3 edit

Differences ...

==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/add.h#6 (text+ko) ====

@@ -40,16 +40,9 @@
 extern Boolean	FailOnAlreadyInstalled;
 extern Boolean	KeepPackage;
 extern Boolean	IgnoreDeps;
-extern char	*Mode;
-extern char	*Owner;
-extern char	*Group;
-extern char	*Directory;
-extern char	*PkgName;
-extern char	*PkgAddCmd;
 extern add_mode_t AddMode;
 
-int	make_hierarchy(char *);
-void	apply_perms(const char *, const char *);
+int	mkdirs(char *path);
 int	extract_package(struct archive *, Package *, const char *);
 int	extract_plist(struct archive *, struct archive_entry *, Package *);
 int	pkg_do(const char *);

==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#13 (text+ko) ====

@@ -301,7 +301,7 @@
 	 */
 	snprintf(db_dir_tmp, sizeof(db_dir_tmp), "%s/.%s", LOG_DIR, pkg->name);
 	snprintf(db_dir, sizeof(db_dir), "%s/%s", LOG_DIR, pkg->name);
-	if (make_hierarchy(db_dir_tmp) == -1) {
+	if (mkdirs(db_dir_tmp) == -1) {
 	    warnx("Can not create '%s' directory - aborting", db_dir_tmp);
 	    return (1);
 	}
@@ -413,7 +413,7 @@
 		    p->name = strdup(prefix);
 		if (Verbose)
 		    printf("extract: CWD to %s\n", p->name);
-		if (!Fake && make_hierarchy(p->name) == -1) {
+		if (!Fake && mkdirs(p->name) == -1) {
 		    warnx("Can not create '%s' directory.", p->name);
 		    return (1);
 		}

==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/futil.c#3 (text+ko) ====

@@ -21,76 +21,37 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/futil.c,v 1.16 2010/04/23 11:07:43 flz Exp $");
 
-#include <err.h>
+#include <errno.h>
 #include <pkg.h>
+
 #include "add.h"
 
 /*
- * Assuming dir is a desired directory name, make it and all intervening
- * directories necessary.
+ * Does the same job as mkdir(1) with the -p flag.
+ * Returns 0 on success, -1 otherwise.
  */
-
 int
-make_hierarchy(char *dir)
+mkdirs(char *path)
 {
-    char *cp1, *cp2;
+	int last;
+	char *p;
 
-    if (dir[0] == '/')
-	cp1 = cp2 = dir + 1;
-    else
-	cp1 = cp2 = dir;
-    while (cp2) {
-	if ((cp2 = strchr(cp1, '/')) !=NULL )
-	    *cp2 = '\0';
-	if (fexists(dir)) {
-	    if (!isdir(dir)) {
-		if (cp2)
-		    *cp2 = '/';
-		return -1;
-	    }
+	p = path;
+	if (p[0] == '/')
+	    ++p;
+	for (last = 0; !last ; ++p) {
+	    if (p[0] == '\0')
+		last = 1;
+	    else if (p[0] != '/')
+		continue;
+	    *p = '\0';
+	    if (!last && p[1] == '\0')
+		last = 1;
+	    if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
+		if (errno != EEXIST && errno != EISDIR)
+		    return (-1);
+	    if (!last)
+		*p = '/';
 	}
-	else {
-	    if (mkdir(dir, 0777) < 0) {
-		if (cp2)
-		    *cp2 = '/';
-		return -1;
-	    }
-	    apply_perms(NULL, dir);
-	}
-	/* Put it back */
-	if (cp2) {
-	    *cp2 = '/';
-	    cp1 = cp2 + 1;
-	}
-    }
-    return 0;
-}
-
-/* Using permission defaults, apply them as necessary */
-void
-apply_perms(const char *dir, const char *arg)
-{
-    const char *cd_to;
-
-    if (!dir || *arg == '/')	/* absolute path? */
-	cd_to = "/";
-    else
-	cd_to = dir;
-
-    if (Mode)
-	if (vsystem("cd %s && /bin/chmod -R %s %s", cd_to, Mode, arg))
-	    warnx("couldn't change modes of '%s' to '%s'", arg, Mode);
-    if (Owner && Group) {
-	if (vsystem("cd %s && /usr/sbin/chown -R %s:%s %s", cd_to, Owner, Group, arg))
-	    warnx("couldn't change owner/group of '%s' to '%s:%s'",
-		   arg, Owner, Group);
-	return;
-    }
-    if (Owner) {
-	if (vsystem("cd %s && /usr/sbin/chown -R %s %s", cd_to, Owner, arg))
-	    warnx("couldn't change owner of '%s' to '%s'", arg, Owner);
-	return;
-    } else if (Group)
-	if (vsystem("cd %s && /usr/bin/chgrp -R %s %s", cd_to, Group, arg))
-	    warnx("couldn't change group of '%s' to '%s'", arg, Group);
+	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008021931.o72JVQGD035785>