git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Try to remove the given path even if it can't be opened

From
Alex Riesen <raa.lkml@gmail.com>
Date
Apr 2, 2011, 20:09 UTC
Message-ID
<20110402200920.GA18171@blimp.dmz>
In-Reply-To
<7vy63tg7yz.fsf@alter.siamese.dyndns.org>

Consider unreadable empty directories. rmdir(2) will remove them just fine, assuming the parent directory is modifiable.

Noticed by Linus. Fix suggested by Michael Gruber and Linus.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
Junio C Hamano, Fri, Apr 01, 2011 20:08:36 +0200:
> 
> Please don't do an attachment that has an inline patch and then attach the
> patch itself again in base64.  It is extremely annoying.
Sorry. Hard to notice on GMail.

The extended error information is a little bit tricky: there is at least four error cases (opendir, stat, unlink and rmdir) and there is a closedir, which resets errno to output the error in the caller of remove_dir_recursively.

 dir.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/dir.c b/dir.c
index 325fb56..532bcb6 100644
--- a/dir.c
+++ b/dir.c
@@ -1192,7 +1192,7 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 
 	dir = opendir(path->buf);
 	if (!dir)
-		return -1;
+		return rmdir(path->buf);
 	if (path->buf[original_len - 1] != '/')
 		strbuf_addch(path, '/');
 
-- 
1.7.4
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “Try to remove the given path even if it can't be opened”
  1. Try to remove the given path even if it can't be openedAlex Riesen, Apr 1, 2011
  2. Michael J GruberApr 1, 2011
  3. Alex RiesenApr 1, 2011
  4. Junio C HamanoApr 1, 2011
  5. Try to remove the given path even if it can't be openedAlex Riesen, Apr 2, 2011
  6. Junio C HamanoApr 2, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.