[BusyBox-cvs] CVS busybox/libbb

CVS User andersen andersen at codepoet.org
Fri Oct 8 07:21:59 UTC 2004


Update of /var/cvs/busybox/libbb
In directory nail:/tmp/cvs-serv7690/libbb

Modified Files:
	make_directory.c 
Log Message:
Patch from Michael Tokarev:

Scenario:

  touch x -- creates plain file name `x'
  mkdir x -- exits successefully

libbb/make_directory.c, bb_make_directory(), contains
the following code:

        if (mkdir(path, 0777) < 0) {
            /* If we failed for any other reason than the directory
             * already exists, output a diagnostic and return -1.*/
            if (errno != EEXIST) {
                fail_msg = "create";
                umask(mask);
                break;
            }
            /* Since the directory exists, don't attempt to change
             * permissions if it was the full target.  Note that
             * this is not an error conditon. */
            if (!c) {
                umask(mask);
                return 0;
            }
        }

The assumption that EEXIST error is due to that the *directory*
already exists is wrong: any file type with that name will cause
this error to be returned.  Proper way IMHO will be is to stat()
the path and check whenever this is really a directory.  Below
(attached) is a patch to fix this issue.



--- /var/cvs/busybox/libbb/make_directory.c	2004/04/14 17:51:15	1.15
+++ /var/cvs/busybox/libbb/make_directory.c	2004/10/08 07:21:58	1.16
@@ -37,6 +37,7 @@
 
 #include <errno.h>
 #include <unistd.h>
+#include <sys/stat.h>
 #include "libbb.h"
 
 int bb_make_directory (char *path, long mode, int flags)
@@ -45,6 +46,7 @@
 	const char *fail_msg;
 	char *s = path;
 	char c;
+	struct stat st;
 
 	mask = umask(0);
 	umask(mask & ~0300);
@@ -70,7 +72,9 @@
 		if (mkdir(path, 0777) < 0) {
 			/* If we failed for any other reason than the directory
 			 * already exists, output a diagnostic and return -1.*/
-			if (errno != EEXIST) {
+			if (errno != EEXIST
+				|| !(flags & FILEUTILS_RECUR)
+				|| (stat(path, &st) < 0 || !S_ISDIR(st.st_mode))) {
 				fail_msg = "create";
 				umask(mask);
 				break;



More information about the busybox-cvs mailing list