]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(remove_dir): If we can't save the state of the
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Jul 2004 14:50:06 +0000 (14:50 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Jul 2004 14:50:06 +0000 (14:50 +0000)
working directory, pretend we started from "/", not ".".
This avoids a bug on hosts like Solaris that don't let you
remove the working directory.

src/remove.c

index 0845e51da450ffe0bfc218fff353e59f533a3cb5..86f08fefd02d9393e1ad0d41906df29d87250fd6 100644 (file)
@@ -1008,9 +1008,12 @@ remove_dir (Dirstack_state *ds, char const *dir, struct cwd_state **cwd_state,
          (*cwd_state)->saved_errno = errno;
          assert (errno != 0);
 
-         /* Pretend we started from ".".  That is fine as long as there
-            is no requirement to return to the original working directory.  */
-         (*cwd_state)->saved_cwd.name = xstrdup (".");
+         /* Pretend we started from "/".  That is fine as long as there
+            is no requirement to return to the original working directory.
+            Use "/", not ".", so that we chdir out of a non-root target
+            directory before attempting to remove it: some hosts don't let
+            you remove a working directory.  */
+         (*cwd_state)->saved_cwd.name = xstrdup ("/");
        }
       else
        (*cwd_state)->saved_errno = 0;