From: Paul Eggert Date: Wed, 28 Jul 2004 14:50:06 +0000 (+0000) Subject: (remove_dir): If we can't save the state of the X-Git-Tag: v5.3.0~1056 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bfb177670771c7e26cdb39e3dcebb056702b00a;p=thirdparty%2Fcoreutils.git (remove_dir): If we can't save the state of the working directory, pretend we started from "/", not ".". This avoids a bug on hosts like Solaris that don't let you remove the working directory. --- diff --git a/src/remove.c b/src/remove.c index 0845e51da4..86f08fefd0 100644 --- a/src/remove.c +++ b/src/remove.c @@ -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;