summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
authortakahashim <[email protected]>2015-12-06 00:07:16 +0900
committertakahashim <[email protected]>2015-12-08 00:29:42 +0900
commitdd754220ce2a53f8cf44362a2b2d1f59f40e62d5 (patch)
tree645df51d35e9932b74f6d8503c34a61670cff987 /mrblib
parent68de1e4fc5a124689e3ad975172c77071e4e63dc (diff)
downloadmruby-dd754220ce2a53f8cf44362a2b2d1f59f40e62d5.tar.gz
mruby-dd754220ce2a53f8cf44362a2b2d1f59f40e62d5.zip
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.
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/file.rb24
-rw-r--r--mrblib/io.rb6
2 files changed, 25 insertions, 5 deletions
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