summaryrefslogtreecommitdiff
path: root/lib/mkdir-p.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-12-23 18:15:33 +0000
committerJim Meyering <jim@meyering.net>2005-12-23 18:15:33 +0000
commit5d3118175fa121b3e43c28eed5360a1800d1a88e (patch)
treeaf0ce7401ec9d19c6e436f8fc189138f68f7af9f /lib/mkdir-p.c
parentbdf801ef2970d82fb7a6a01299a7be11e2c911ab (diff)
downloadcoreutils-5d3118175fa121b3e43c28eed5360a1800d1a88e.tar.xz
(make_dir_parents): Use chdir_no_follow only
if we've just created the directory.
Diffstat (limited to 'lib/mkdir-p.c')
-rw-r--r--lib/mkdir-p.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/mkdir-p.c b/lib/mkdir-p.c
index 1fd577994..83c2aa65f 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)
{