automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: case sensitive file checks


From: Alexandre Duret-Lutz
Subject: Re: case sensitive file checks
Date: Wed, 08 Dec 2004 02:07:34 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

>>> "adl" == Alexandre Duret-Lutz <address@hidden> writes:

[...]

 adl> It takes about 45 minutes these days on my not-so-new 2GHz
 adl> Athlon.

Perhaps I should have waited those 45 minutes before sending the
patch :)

The addition here is the call to reset_dir_cache when a new file
has been added.

make check is still running but my bed won't wait another 45min.

2004-12-08  Peter O'Gorman  <address@hidden>
            Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/FileUtils.pm (dir_has_case_matching_file,
        reset_dir_cache): New functions.
        * automake.in (handle_dist, require_file_internal): Use them, so
        that CHANGELOG is not confused with ChangeLog on case-insensitive
        case-preserving file systems.
        * tests/hfs.test: New file.
        * tests/Makefile.am (TESTS): Add hfs.test.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1569.2.6
diff -u -r1.1569.2.6 automake.in
--- automake.in 21 Oct 2004 21:37:52 -0000      1.1569.2.6
+++ automake.in 8 Dec 2004 01:02:54 -0000
@@ -3468,7 +3468,7 @@
     }
   foreach my $cfile (@common_files)
     {
-      if (-f ($relative_dir . "/" . $cfile)
+      if (dir_has_case_matching_file ($relative_dir, $cfile)
          # The file might be absent, but if it can be built it's ok.
          || rule $cfile)
        {
@@ -3477,7 +3477,7 @@
 
       # Don't use `elsif' here because a file might meaningfully
       # appear in both directories.
-      if ($check_aux && -f "$config_aux_dir/$cfile")
+      if ($check_aux && dir_has_case_matching_file ($config_aux_dir, $cfile))
        {
          &push_dist_common ("$config_aux_dir/$cfile")
        }
@@ -6842,7 +6842,7 @@
        {
          $dangling_sym = 1;
        }
-      elsif (-f $fullfile)
+      elsif (dir_has_case_matching_file ($dir, $file))
        {
          $found_it = 1;
          maybe_push_required_file ($dir, $file, $fullfile);
@@ -6906,6 +6906,7 @@
                          $suppress = 0;
                          $trailer = "\n    error while copying";
                        }
+                     reset_dir_cache ($dir);
                    }
 
                  if (! maybe_push_required_file (dirname ($fullfile),
Index: lib/Automake/FileUtils.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/FileUtils.pm,v
retrieving revision 1.4
diff -u -r1.4 FileUtils.pm
--- lib/Automake/FileUtils.pm   12 Sep 2003 08:37:57 -0000      1.4
+++ lib/Automake/FileUtils.pm   8 Dec 2004 01:02:54 -0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2003  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004  Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@
 @EXPORT = qw (&contents
              &find_file &mtime
              &update_file &up_to_date_p
-             &xsystem &xqx);
+             &xsystem &xqx &dir_has_case_matching_file &reset_dir_cache);
 
 
 =item C<find_file ($filename, @include)>
@@ -310,6 +310,58 @@
 }
 
 
+=item C<dir_has_case_matching_file ($DIRNAME, $FILENAME)>
+
+Return true iff $DIR contains a filename that matches $FILENAME case
+insensitively.
+
+We need to be cautious on case-insensitive case-preserving file
+systems (e.g. Mac OS X's HFS+).  On such systems C<-f 'Foo'> and C<-f
+'foO'> answer the same thing.  Hence if a package distributes its own
+F<CHANGELOG> file, but has no F<ChangeLog> file, automake would still
+try to distribute F<ChangeLog> (because it thinks it exists) in
+addition to F<CHANGELOG>, although it is impossible for these two
+files to be in the same directory (the two filenames designate the
+same file).
+
+=cut
+
+use vars '%_directory_cache';
+sub dir_has_case_matching_file ($$)
+{
+  # Note that print File::Spec->case_tolerant returns 0 even on MacOS
+  # X (with Perl v5.8.1-RC3 at least), so do not try to shortcut this
+  # function using that.
+
+  my ($dirname, $filename) = @_;
+  return 0 unless -f "$dirname/$filename";
+
+  # The file appears to exist, however it might be a mirage if the
+  # system is case insensitive.  Let's browse the directory and check
+  # whether the file is really in.  We maintain a cache of directories
+  # so Automake doesn't spend all its time reading the same directory
+  # again and again.
+  if (!exists $_directory_cache{$dirname})
+    {
+      error "failed to open directory `$dirname'"
+       unless opendir (DIR, $dirname);
+      $_directory_cache{$dirname} = { map { $_ => 1 } readdir (DIR) };
+      closedir (DIR);
+    }
+  return exists $_directory_cache{$dirname}{$filename};
+}
+
+=item C<reset_dir_cache ($DIRNAME)>
+
+Clear dir_has_case_matching_file's cache for $DIRNAME.
+
+=cut
+
+sub reset_dir_cache ($)
+{
+  delete $_directory_cache{$_[0]};
+}
+
 1; # for require
 
 ### Setup "GNU" style for perl-mode and cperl-mode.
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.565.2.7
diff -u -r1.565.2.7 Makefile.am
--- tests/Makefile.am   5 Dec 2004 16:12:43 -0000       1.565.2.7
+++ tests/Makefile.am   8 Dec 2004 01:02:54 -0000
@@ -247,6 +247,7 @@
 gnits3.test \
 header.test \
 help.test \
+hfs.test \
 hosts.test \
 implicit.test \
 include.test \
Index: tests/Makefile.in
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.in,v
retrieving revision 1.733.2.15
diff -u -r1.733.2.15 Makefile.in
--- tests/Makefile.in   5 Dec 2004 16:12:43 -0000       1.733.2.15
+++ tests/Makefile.in   8 Dec 2004 01:02:55 -0000
@@ -366,6 +366,7 @@
 gnits3.test \
 header.test \
 help.test \
+hfs.test \
 hosts.test \
 implicit.test \
 include.test \
Index: tests/hfs.test
===================================================================
RCS file: tests/hfs.test
diff -N tests/hfs.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/hfs.test      8 Dec 2004 01:02:55 -0000
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2004  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+
+# Automake should not think that ChangeLog == CHANGELOG on
+# case-preserving case-insensitive filesystems (such as HFS+, on
+# Darwin).
+# Report from Peter O'Gorman.
+
+. ./defs
+set -e
+
+echo AC_OUTPUT >>configure.in
+
+: >CHANGELOG
+echo 'EXTRA_DIST = CHANGELOG' >Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]