You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2005/09/25 00:09:40 UTC

svn commit: r291339 - in /apr/apr/trunk: file_io/unix/dir.c test/testdir.c

Author: jorton
Date: Sat Sep 24 15:09:35 2005
New Revision: 291339

URL: http://svn.apache.org/viewcvs?rev=291339&view=rev
Log:
* file_io/unix/dir.c (apr_dir_make_recursive): Fix infinite recursion
if mkdir fails for all path components.

* test/testdir.c (test_rmkdir_nocwd): Add test case.

Modified:
    apr/apr/trunk/file_io/unix/dir.c
    apr/apr/trunk/test/testdir.c

Modified: apr/apr/trunk/file_io/unix/dir.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/unix/dir.c?rev=291339&r1=291338&r2=291339&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/dir.c (original)
+++ apr/apr/trunk/file_io/unix/dir.c Sat Sep 24 15:09:35 2005
@@ -312,6 +312,11 @@
         char *dir;
         
         dir = path_remove_last_component(path, pool);
+        /* If there is no path left, give up. */
+        if (dir[0] == '\0') {
+            return apr_err;
+        }
+
         apr_err = apr_dir_make_recursive(dir, perm, pool);
         
         if (!apr_err) 

Modified: apr/apr/trunk/test/testdir.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/test/testdir.c?rev=291339&r1=291338&r2=291339&view=diff
==============================================================================
--- apr/apr/trunk/test/testdir.c (original)
+++ apr/apr/trunk/test/testdir.c Sat Sep 24 15:09:35 2005
@@ -219,6 +219,30 @@
 
 }
 
+static void test_rmkdir_nocwd(abts_case *tc, void *data)
+{
+    char *cwd, *path;
+
+    APR_ASSERT_SUCCESS(tc, "make temp dir",
+                       apr_dir_make("dir3", APR_OS_DEFAULT, p));
+
+    APR_ASSERT_SUCCESS(tc, "obtain cwd", apr_filepath_get(&cwd, 0, p));
+
+    APR_ASSERT_SUCCESS(tc, "determine path to temp dir",
+                       apr_filepath_merge(&path, cwd, "dir3", 0, p));
+
+    APR_ASSERT_SUCCESS(tc, "change to temp dir", apr_filepath_set(path, p));
+
+    APR_ASSERT_SUCCESS(tc, "remove temp dir", apr_dir_remove(path, p));
+
+    ABTS_ASSERT(tc, "fail to create dir",
+                apr_dir_make_recursive("foobar", APR_OS_DEFAULT, 
+                                       p) != APR_SUCCESS);
+
+    APR_ASSERT_SUCCESS(tc, "restore cwd", apr_filepath_set(cwd, p));
+}
+
+
 abts_suite *testdir(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -230,6 +254,7 @@
     abts_run_test(suite, test_removeall, NULL);
     abts_run_test(suite, test_remove_notthere, NULL);
     abts_run_test(suite, test_mkdir_twice, NULL);
+    abts_run_test(suite, test_rmkdir_nocwd, NULL);
 
     abts_run_test(suite, test_rewind, NULL);