While trying to delete an invalid symbolic link file (for which the linked
file is deleted), delete-file function succeeds, while delete-file* returns
false.
I have conducted research which showed me that file-exists? with such
invalid link also returns false, as it calls stat, and, therefore, follows
symbolic links.
I have prepared a patch which replaces stat with lstat. If that approach is
not acceptable, I can try to fix it in a more preferred way.

How to reproduce:
$ touch some-file
$ ln -s some-file some-link
$ rm some-file
$ csi -e '(import (chicken file)) (print (file-exists? "some-link"))'

P.S. I tried creating a ticket, but bugtracker responds with 500 HTTP code.
From b9dcc774f4b79fe87a04e01275a2049c198bad3b Mon Sep 17 00:00:00 2001
From: fa11-1eaf <[email protected]>
Date: Thu, 1 Jan 2026 11:27:20 +0300
Subject: [PATCH] replaced stat system calls with lstat in order to correctly
 process symbolic links

---
 chicken.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chicken.h b/chicken.h
index f6403c40..b33c69be 100644
--- a/chicken.h
+++ b/chicken.h
@@ -3698,7 +3698,7 @@ inline static int C_stat(const char *path, struct stat *buf)
   size_t len = C_strlen(path);
   char slash = len && path[len - 1] == '/';
 
-  if(stat(path, buf) != 0) {
+  if(lstat(path, buf) != 0) {
     return -1;
   }
 
@@ -3710,7 +3710,7 @@ inline static int C_stat(const char *path, struct stat *buf)
   return 0;
 }
 #else
-# define C_stat stat
+# define C_stat lstat
 #endif
 
 /* Safe realpath usage depends on a reliable PATH_MAX. */
-- 
2.51.0

Reply via email to