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

[PATCH] builtin/clean.c: Handle disappearing files

From
David Turner <dturner@twopensource.com>
Date
May 14, 2015, 21:16 UTC
Message-ID
<1431638200-20449-1-git-send-email-dturner@twitter.com>

During a git clean, some other process might be deleting files as well. If this happens, make git clean no longer die.

Signed-off-by: David Turner <dturner@twitter.com>
---
 builtin/clean.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/builtin/clean.c b/builtin/clean.c
index 98c103f..3ae44c2 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -941,8 +941,16 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 		if (!cache_name_is_other(ent->name, ent->len))
 			continue;
 
-		if (lstat(ent->name, &st))
-			die_errno("Cannot lstat '%s'", ent->name);
+		/*
+		 * Some concurrent process might have already removed
+		 * ent->name.
+		 */
+		if (lstat(ent->name, &st)) {
+			if (errno == ENOENT || errno == ENOTDIR)
+				continue;
+			else
+				die_errno("Cannot lstat '%s'", ent->name);
+		}
 
 		if (pathspec.nr)
 			matches = dir_path_match(ent, &pathspec, 0, NULL);
-- 
2.0.4.315.gad8727a-twtrsrc
Next: Junio C Hamano
Message 1 of 8 in “builtin/clean.c: Handle disappearing files”
  1. builtin/clean.c: Handle disappearing filesDavid Turner, May 14, 2015
  2. Junio C HamanoMay 14, 2015
  3. David TurnerMay 14, 2015
  4. Junio C HamanoMay 14, 2015
  5. David TurnerMay 14, 2015
  6. Junio C HamanoMay 15, 2015
  7. David TurnerMay 15, 2015
  8. Junio C HamanoMay 16, 2015

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.