From dd754220ce2a53f8cf44362a2b2d1f59f40e62d5 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sun, 6 Dec 2015 00:07:16 +0900 Subject: Fix for windows(mingw) * File.expand_path: support drive letter and ALT_SEPARATOR * File.dirname: support ALT_SEPARATOR * File.basename: ditto. * IO.popen: raise NotImplementedError * IO.pipe: ditto. * `cmd`: ditto. * File#flock: ditto. * FileTest.pipe?: ditto. * FileTest.symlink?: ditto. * FileTest.socket?: ditto. --- mrblib/file.rb | 24 +++++++++++++++++++----- mrblib/io.rb | 6 ++++++ 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'mrblib') diff --git a/mrblib/file.rb b/mrblib/file.rb index f644ff691..86074c3e3 100644 --- a/mrblib/file.rb +++ b/mrblib/file.rb @@ -89,14 +89,21 @@ class File < IO end expanded_path = concat_path(path, default_dir) + drive_prefix = "" + if File::ALT_SEPARATOR && expanded_path.size > 2 && + ("A".."Z").include?(expanded_path[0].upcase) && expanded_path[1] == ":" + drive_prefix = expanded_path[0, 2] + expanded_path = expanded_path[2, expanded_path.size] + end expand_path_array = [] + if File::ALT_SEPARATOR && expanded_path.include?(File::ALT_SEPARATOR) + expanded_path.gsub!(File::ALT_SEPARATOR, '/') + end while expanded_path.include?('//') expanded_path = expanded_path.gsub('//', '/') end - if expanded_path == "/" - expanded_path - else + if expanded_path != "/" expanded_path.split('/').each do |path_token| if path_token == '..' if expand_path_array.size > 1 @@ -109,8 +116,15 @@ class File < IO end end - expand_path = expand_path_array.join("/") - expand_path.empty? ? '/' : expand_path + expanded_path = expand_path_array.join("/") + if expanded_path.empty? + expanded_path = '/' + end + end + if drive_prefix.empty? + expanded_path + else + drive_prefix + expanded_path.gsub("/", File::ALT_SEPARATOR) end end diff --git a/mrblib/io.rb b/mrblib/io.rb index 1742fac32..755dbbf6d 100644 --- a/mrblib/io.rb +++ b/mrblib/io.rb @@ -27,6 +27,9 @@ class IO end def self.popen(command, mode = 'r', &block) + if !self.respond_to?(:_popen) + raise NotImplementedError, "popen is not supported on this platform" + end io = self._popen(command, mode) return io unless block @@ -42,6 +45,9 @@ class IO end def self.pipe(&block) + if !self.respond_to?(:_pipe) + raise NotImplementedError, "pipe is not supported on this platform" + end if block begin r, w = IO._pipe -- cgit v1.2.3