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

[PATCH] file_exists(): dangling symlinks do exist

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 18, 2007, 10:21 UTC
Message-ID
<1195381287-26823-1-git-send-email-gitster@pobox.com>

This function is used to see if a path given by the user does exist on the filesystem. A symbolic link that does not point anywhere does exist but running stat() on it would yield an error, and it incorrectly said it does not exist.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 dir.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/dir.c b/dir.c
index 01790ab..87e5dec 100644
--- a/dir.c
+++ b/dir.c
@@ -688,11 +688,10 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i
 	return dir->nr;
 }
 
-int
-file_exists(const char *f)
+int file_exists(const char *f)
 {
-  struct stat sb;
-  return stat(f, &sb) == 0;
+	struct stat sb;
+	return lstat(f, &sb) == 0;
 }
 
 /*
-- 
1.5.3.5.1815.g9445b
Next: Junio C Hamano
Message 1 of 8 in “file_exists(): dangling symlinks do exist”
  1. file_exists(): dangling symlinks do existJunio C Hamano, Nov 18, 2007
  2. Export three helper functions from ls-filesJunio C Hamano, Nov 18, 2007
  3. Fix add_files_to_cache() to take pathspec, not user specified list of filesJunio C Hamano, Nov 18, 2007
  4. builtin-commit: fix partial-commit supportJunio C Hamano, Nov 18, 2007
  5. Junio C HamanoNov 18, 2007
  6. Junio C HamanoNov 18, 2007
  7. Junio C HamanoNov 18, 2007
  8. Kristian HøgsbergNov 19, 2007

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.