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

ruby-changes:47863

From: nobu <ko1@a...>
Date: Thu, 21 Sep 2017 16:29:24 +0900 (JST)
Subject: [ruby-changes:47863] nobu:r59984 (trunk): load.c: real path to load

nobu	2017-09-21 16:29:20 +0900 (Thu, 21 Sep 2017)

  New Revision: 59984

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59984

  Log:
    load.c: real path to load
    
    * load.c (rb_construct_expanded_load_path): expand load paths to
      real paths to get rid of duplicate loading from symbolic-linked
      directories.  [Feature #10222]

  Modified files:
    trunk/load.c
    trunk/test/ruby/test_exception.rb
    trunk/test/ruby/test_require.rb
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 59983)
+++ test/ruby/test_exception.rb	(revision 59984)
@@ -1019,7 +1019,7 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1019
     warning = nil
     path = nil
     Tempfile.create(%w[circular .rb]) do |t|
-      path = t.path
+      path = File.realpath(t.path)
       basename = File.basename(path)
       t.puts "require '#{basename}'"
       t.close
Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 59983)
+++ test/ruby/test_require.rb	(revision 59984)
@@ -881,4 +881,18 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L881
       end;
     end
   end
+
+  def test_symlink_load_path
+    Dir.mktmpdir {|tmp|
+      Dir.mkdir(File.join(tmp, "real"))
+      begin
+        File.symlink "real", File.join(tmp, "symlink")
+      rescue NotImplementedError, Errno::EACCES
+        skip "File.symlink is not implemented"
+      end
+      File.write(File.join(tmp, "real/a.rb"), "print __FILE__")
+      result = IO.popen([EnvUtil.rubybin, "-I#{tmp}/symlink", "-e", "require 'a.rb'"], &:read)
+      assert_operator(result, :end_with?, "/real/a.rb")
+    }
+  end
 end
Index: load.c
===================================================================
--- load.c	(revision 59983)
+++ load.c	(revision 59984)
@@ -85,7 +85,8 @@ rb_construct_expanded_load_path(enum exp https://github.com/ruby/ruby/blob/trunk/load.c#L85
 	if (is_string)
 	    rb_str_freeze(path);
 	as_str = rb_get_path_check_convert(path, as_str, level);
-	expanded_path = rb_file_expand_path_fast(as_str, Qnil);
+	expanded_path = rb_check_realpath(Qnil, as_str);
+	if (NIL_P(expanded_path)) expanded_path = as_str;
 	rb_ary_push(ary, rb_fstring(expanded_path));
     }
     rb_obj_freeze(ary);

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

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