From: Luis Lavena Date: 2011-01-30T11:01:29+09:00 Subject: [ruby-core:34991] Understanding realpath_rec behavior Hello, Some developers at RubyInstaller group have been started to dig into Ruby C code to better under the quantity of API calls performed under Windows. Part of this quest, some questions raised in relation to realpath_rec behavior and how it stat every single directory in a PATH. For example: (with cwd been C:\Users\Luis\Projects\oss\oci\rubyinstaller\sandbox) irb> File.realpath('foo.rb') Will generate 7 lstat() requests -- in our case winnt_stat -- each one for a part of the path: C:/Users C:/Users/Luis C:/Users/Projects C:/Users/Projects/oss C:/Users/Projects/oss/oci C:/Users/Projects/oss/oci/rubyinstaller C:/Users/Projects/oss/oci/rubyinstaller/foo.rb As I understand the purpose of this: - It iterates over each individual directory to determine if the directory exist, and if so, in the case of a link, perform readlink() on it and resolve it. - It collects in loopcheck the traversal to avoid recursive lookup which could only happen in the case of links. - It triggers ENOENT early as possible. Windows lacks readlink() functionality, so while even excluding the readlink() part, still the traversal is performed. There is also an evaluation of . and .., but all the paths arriving to realpath_rec has already been expanded. I've tried "../sandbox/foo.rb" and "./foo.rb" all resulted in the same quantity of lstat() invocations. Is all the above correct? I'm missing something in the purpose of realpath_rec? In case all my observations are correct, I think realpath_rec should be changed to a platform specific implementation for Windows inside win32/win32.c that resolves the lookup accordingly to Windows API. While Windows provides symlink/hardlink and junction points interface, adapt Ruby codebase to consider those [1] and take advantage of them would be very extensive modification, not to mention the change in behavior that will cause to Ruby users on Windows [2]. Please let me know your thoughts, comments and feedback on this so we can start looking into an alternative mechanism Windows-specific. Thank you. [1] http://msdn.microsoft.com/en-us/library/aa365680(VS.85).aspx [2] http://msdn.microsoft.com/en-us/library/aa365682(v=VS.85).aspx -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup�ry