From: Jim Meyering Date: Fri, 23 Dec 2005 18:15:33 +0000 (+0000) Subject: (make_dir_parents): Use chdir_no_follow only X-Git-Tag: v6.0~1041 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5d3118175fa121b3e43c28eed5360a1800d1a88e;p=thirdparty%2Fcoreutils.git (make_dir_parents): Use chdir_no_follow only if we've just created the directory. --- diff --git a/lib/mkdir-p.c b/lib/mkdir-p.c index 1fd5779946..83c2aa65fd 100644 --- a/lib/mkdir-p.c +++ b/lib/mkdir-p.c @@ -222,7 +222,14 @@ make_dir_parents (char const *arg, mkdir process O(n^2) file name components. */ if (do_chdir) { - if (chdir_no_follow (basename_dir) == 0) + /* If we know that basename_dir is a directory (because we've + just created it), then ensure that when we change to it, + that final component is not a symlink. Otherwise, we must + accept the possibility that basename_dir is a preexisting + symlink-to-directory and chdir through the symlink. */ + if ((dir_known_to_exist + ? chdir_no_follow (basename_dir) + : chdir (basename_dir)) == 0) dir_known_to_exist = true; else if (dir_known_to_exist) {