Subject: bug#32246: 27.0.50; files-tests failure on Cygwin

From: Ken Brown <[email-masked]>
Date: Fri, 27 Jul 2018 14:34:41 -0400

On 7/26/2018 11:03 AM, Michael Albinus wrote:
> The doc speaks from "the underlying filesystem". So I believe *this*
> must be checked. For non-existing files, the respective directory (up to
> the part which exist) should be checked. In case of
> "/non-existing-dir/non-existing-file", "/" must be checked.

Thanks, that makes sense.  Patch attached.

Ken
From 8f8c1050509f88f38f6c2b1681c969b1e9922413 Mon Sep 17 00:00:00 2001
From: Ken Brown <[email-masked]>
Date: Fri, 27 Jul 2018 14:24:01 -0400
Subject: [PATCH] Fix file-name-case-insensitive-p on non-existent files

* src/fileio.c (Ffile_name_case_insensitive_p): If the file
doesn't exist, move up the filesystem tree until an existing
directory is found.  Then test that directory for
case-insensitivity.  (Bug#32246)
---
 src/fileio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/fileio.c b/src/fileio.c
index b92492c93a..2dcfb73b0d 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2296,6 +2296,21 @@ The arg must be a string.  */)
   if (!NILP (handler))
     return call2 (handler, Qfile_name_case_insensitive_p, filename);
 
+  /* If the file doesn't exist, move up the filesystem tree until we
+     reach an existing directory or the root.  */
+  if (NILP (Ffile_exists_p (filename)))
+    {
+      filename = Ffile_name_directory (filename);
+      while (NILP (Ffile_exists_p (filename)))
+	{
+	  Lisp_Object newname = expand_and_dir_to_file (filename);
+	  /* Avoid infinite loop if the root is reported as non-existing
+	     (impossible?).  */
+	  if (!NILP (Fstring_equal (newname, filename)))
+	    break;
+	  filename = newname;
+	}
+    }
   filename = ENCODE_FILE (filename);
   return file_name_case_insensitive_p (SSDATA (filename)) ? Qt : Qnil;
 }
-- 
2.17.0