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

[PATCH] entry: check for fstat() errors after checkout

From
Matheus Tavares <matheus.bernardino@usp.br>
Date
Jul 9, 2020, 02:10 UTC
Message-ID
<fbde5e1c9042ea06b448bc759cea9d45e300961f.1594260597.git.matheus.bernardino@usp.br>

In 11179eb311 ("entry.c: check if file exists after checkout", 2017-10-05) we started checking the result of the lstat() call done after writing a file, to avoid writing garbage to the corresponding cache entry. However, the code skips calling lstat() if it's possible to use fstat() when it still has the file descriptor open. And when calling fstat() we don't do the same error checking. To fix that, let the callers of fstat_output() know when fstat() fails. In this case, write_entry() will try to use lstat() and properly report an error if that fails as well.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 entry.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/entry.c b/entry.c
index 00b4903366..449bd32dee 100644
--- a/entry.c
+++ b/entry.c
@@ -113,8 +113,7 @@ static int fstat_output(int fd, const struct checkout *state, struct stat *st)
 	/* use fstat() only when path == ce->name */
 	if (fstat_is_reliable() &&
 	    state->refresh_cache && !state->base_dir_len) {
-		fstat(fd, st);
-		return 1;
+		return !fstat(fd, st);
 	}
 	return 0;
 }
-- 
2.27.0
Next: Derrick Stolee
Message 1 of 9 in “entry: check for fstat() errors after checkout”
  1. entry: check for fstat() errors after checkoutMatheus Tavares, Jul 9, 2020
  2. Derrick StoleeJul 9, 2020
  3. Junio C HamanoJul 9, 2020
  4. Junio C HamanoJul 9, 2020
  5. Matheus Tavares BernardinoJul 9, 2020
  6. Junio C HamanoJul 9, 2020
  7. Matheus Tavares BernardinoJul 21, 2020
  8. Junio C HamanoJul 21, 2020
  9. Derrick StoleeJul 21, 2020

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.