[前][次][番号順一覧][スレッド一覧]

ruby-changes:19054

From: nobu <ko1@a...>
Date: Fri, 11 Mar 2011 18:51:55 +0900 (JST)
Subject: [ruby-changes:19054] Ruby:r31092 (trunk): * lib/mkmf.rb (find_executable0): should exclude directories.

nobu	2011-03-11 18:42:46 +0900 (Fri, 11 Mar 2011)

  New Revision: 31092

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31092

  Log:
    * lib/mkmf.rb (find_executable0): should exclude directories.

  Modified files:
    trunk/ChangeLog
    trunk/lib/mkmf.rb
    trunk/test/mkmf/test_find_executable.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31091)
+++ ChangeLog	(revision 31092)
@@ -1,3 +1,7 @@
+Fri Mar 11 18:42:43 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/mkmf.rb (find_executable0): should exclude directories.
+
 Fri Mar 11 01:40:35 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* process.c (proc_getmaxgroups, proc_setmaxgroups): Process#maxgroups
Index: lib/mkmf.rb
===================================================================
--- lib/mkmf.rb	(revision 31091)
+++ lib/mkmf.rb	(revision 31092)
@@ -1327,11 +1327,20 @@
 # Internal use only.
 #
 def find_executable0(bin, path = nil)
+  executable_file = proc do |name|
+    begin
+      stat = File.stat(name)
+    rescue SystemCallError
+    else
+      next name if stat.file? and stat.executable?
+    end
+  end
+
   exts = config_string('EXECUTABLE_EXTS') {|s| s.split} || config_string('EXEEXT') {|s| [s]}
   if File.expand_path(bin) == bin
-    return bin if File.executable?(bin)
+    return bin if executable_file.call(bin)
     if exts
-      exts.each {|ext| File.executable?(file = bin + ext) and return file}
+      exts.each {|ext| executable_file.call(file = bin + ext) and return file}
     end
     return nil
   end
@@ -1342,9 +1351,9 @@
   end
   file = nil
   path.each do |dir|
-    return file if File.executable?(file = File.join(dir, bin))
+    return file if executable_file.call(file = File.join(dir, bin))
     if exts
-      exts.each {|ext| File.executable?(ext = file + ext) and return ext}
+      exts.each {|ext| executable_file.call(ext = file + ext) and return ext}
     end
   end
   nil
Index: test/mkmf/test_find_executable.rb
===================================================================
--- test/mkmf/test_find_executable.rb	(revision 31091)
+++ test/mkmf/test_find_executable.rb	(revision 31092)
@@ -2,10 +2,18 @@
 
 class TestMkmf
   class TestFindExecutable < TestMkmf
+    def setup
+      super
+      @path, ENV["PATH"] = ENV["PATH"], @tmpdir
+    end
+
+    def teardown
+      ENV["PATH"] = @path
+      super
+    end
+
     def test_find_executable
       bug2669 = '[ruby-core:27912]'
-      path, ENV["PATH"] = ENV["PATH"], path
-      ENV["PATH"] = @tmpdir
       name = "foobar#{$$}#{rand(1000)}"
       exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
       stdout.filter {|s| s.sub(name, "<executable>")}
@@ -20,8 +28,23 @@
         end
         assert_equal("#{@tmpdir}/#{name}#{ext}", result, bug2669)
       end
-    ensure
-      ENV["PATH"] = path
     end
+
+    def test_find_executable_dir
+      name = "foobar#{$$}#{rand(1000)}"
+      exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
+      stdout.filter {|s| s.sub(name, "<executable>")}
+      exts[0] ||= ""
+      exts.each do |ext|
+        full = name+ext
+        begin
+          Dir.mkdir(full)
+          result = mkmf {find_executable(name)}
+        ensure
+          Dir.rmdir(full)
+        end
+        assert_nil(result)
+      end
+    end
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]