documentation patch for Dir::glob

"Tim Harper" <[email protected]> Thu, 2 Aug 2007 20:30:00 -0600
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <003301c7d576$31f649b0$95e2dd10$@com>
I was surprised earlier to find out that Dir::glob returns recursive results
in a different order given different operating systems.  For example:

 

Consider the following directory structure:

 

dir/file1.txt

dir/file2.txt

a_file.txt

file1.txt

file2.txt

 

Running the command Dir["**/*"] on Windows and Linux will output the
following: 

a_file.txt

file1.txt

file2.txt

dir/file1.txt

dir/file2.txt

 

However, Darwin will just sort the whole thing alphabetically.

a_file.txt

dir/file1.txt

dir/file2.txt

file1.txt

file2.txt

 

This important difference makes it difficult to recursively load Ruby files
that depend on parent files being loaded before child files.

 

Here is a patch for the documentation of Dir::glob, with a small disclaimer
informing users that they can't count on the order of Dir::glob.  It's
patched for both 1.8 and trunk.

 

Thanks,

 

Tim
dir.c.documentation.1.8.patch (application/octet-stream, 674 B)
Index: dir.c
===================================================================
--- dir.c	(revision 12869)
+++ dir.c	(working copy)
@@ -1699,6 +1699,10 @@
  *  parameter. Note that case sensitivity depends on your system (so
  *  <code>File::FNM_CASEFOLD</code> is ignored)
  *
+ *  Note: The order which files are returned are platform-specific.  
+ *  If the order which files are recursed is important to your 
+ *  application, you must sort them after. 
+ *
  *  <code>*</code>::        Matches any file. Can be restricted by
  *                          other values in the glob. <code>*</code>
  *                          will match all files; <code>c*</code> will
dir.c.documentation.trunk.patch (application/octet-stream, 674 B)
Index: dir.c
===================================================================
--- dir.c	(revision 12869)
+++ dir.c	(working copy)
@@ -1619,6 +1619,10 @@
  *  parameter. Note that case sensitivity depends on your system (so
  *  <code>File::FNM_CASEFOLD</code> is ignored)
  *
+ *  Note: The order which files are returned are platform-specific.  
+ *  If the order which files are recursed is important to your 
+ *  application, you must sort them after. 
+ *
  *  <code>*</code>::        Matches any file. Can be restricted by
  *                          other values in the glob. <code>*</code>
  *                          will match all files; <code>c*</code> will