From 5d3118175fa121b3e43c28eed5360a1800d1a88e Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 23 Dec 2005 18:15:33 +0000 Subject: [PATCH] (make_dir_parents): Use chdir_no_follow only if we've just created the directory. --- lib/mkdir-p.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) { -- 2.47.3