ruby-changes:50728
From: nagachika <ko1@a...>
Date: Fri, 23 Mar 2018 21:04:04 +0900 (JST)
Subject: [ruby-changes:50728] nagachika:r62903 (ruby_2_4): merge revision(s) 62607: [Backport #14557]
nagachika 2018-03-23 21:03:58 +0900 (Fri, 23 Mar 2018) New Revision: 62903 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62903 Log: merge revision(s) 62607: [Backport #14557] file.c: realpath on special symlink * file.c (realpath_rec): fallback to symlink path when it is accessible but the link target is not actual entry on file systems. [ruby-dev:50487] [Bug #14557] Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/file.c branches/ruby_2_4/test/ruby/test_file.rb branches/ruby_2_4/version.h Index: ruby_2_4/file.c =================================================================== --- ruby_2_4/file.c (revision 62902) +++ ruby_2_4/file.c (revision 62903) @@ -3778,7 +3778,7 @@ enum rb_realpath_mode { https://github.com/ruby/ruby/blob/trunk/ruby_2_4/file.c#L3778 }; static int -realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, +realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE fallback, VALUE loopcheck, enum rb_realpath_mode mode, int last) { const char *pend = unresolved + strlen(unresolved); @@ -3841,6 +3841,12 @@ realpath_rec(long *prefixlenp, VALUE *re https://github.com/ruby/ruby/blob/trunk/ruby_2_4/file.c#L3841 #endif if (ret == -1) { int e = errno; + if (e == ENOENT && !NIL_P(fallback)) { + if (rb_stat(fallback, &sbuf) == 0) { + rb_str_replace(*resolvedp, fallback); + return 0; + } + } if (mode == RB_REALPATH_CHECK) return -1; if (e == ENOENT) { if (mode == RB_REALPATH_STRICT || !last || *unresolved_firstsep) @@ -3872,7 +3878,7 @@ realpath_rec(long *prefixlenp, VALUE *re https://github.com/ruby/ruby/blob/trunk/ruby_2_4/file.c#L3878 *resolvedp = link; *prefixlenp = link_prefixlen; } - if (realpath_rec(prefixlenp, resolvedp, link_names, + if (realpath_rec(prefixlenp, resolvedp, link_names, testpath, loopcheck, mode, !*unresolved_firstsep)) return -1; RB_GC_GUARD(link_orig); @@ -3960,14 +3966,14 @@ rb_check_realpath_internal(VALUE basedir https://github.com/ruby/ruby/blob/trunk/ruby_2_4/file.c#L3966 loopcheck = rb_hash_new(); if (curdir_names) { - if (realpath_rec(&prefixlen, &resolved, curdir_names, loopcheck, mode, 0)) + if (realpath_rec(&prefixlen, &resolved, curdir_names, Qnil, loopcheck, mode, 0)) return Qnil; } if (basedir_names) { - if (realpath_rec(&prefixlen, &resolved, basedir_names, loopcheck, mode, 0)) + if (realpath_rec(&prefixlen, &resolved, basedir_names, Qnil, loopcheck, mode, 0)) return Qnil; } - if (realpath_rec(&prefixlen, &resolved, path_names, loopcheck, mode, 1)) + if (realpath_rec(&prefixlen, &resolved, path_names, Qnil, loopcheck, mode, 1)) return Qnil; if (origenc != enc && rb_enc_str_asciionly_p(resolved)) Index: ruby_2_4/test/ruby/test_file.rb =================================================================== --- ruby_2_4/test/ruby/test_file.rb (revision 62902) +++ ruby_2_4/test/ruby/test_file.rb (revision 62903) @@ -284,6 +284,14 @@ class TestFile < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_file.rb#L284 } end + def test_realpath_special_symlink + IO.pipe do |r, w| + if File.pipe?(path = "/dev/fd/#{r.fileno}") + assert_file.identical?(File.realpath(path), path) + end + end + end + def test_realdirpath Dir.mktmpdir('rubytest-realdirpath') {|tmpdir| realdir = File.realpath(tmpdir) Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 62902) +++ ruby_2_4/version.h (revision 62903) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.4" -#define RUBY_RELEASE_DATE "2018-03-22" -#define RUBY_PATCHLEVEL 282 +#define RUBY_RELEASE_DATE "2018-03-23" +#define RUBY_PATCHLEVEL 283 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 3 -#define RUBY_RELEASE_DAY 22 +#define RUBY_RELEASE_DAY 23 #include "ruby/version.h" Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 62902) +++ ruby_2_4 (revision 62903) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r62607 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/