diff --git a/src/main/ruby/truffleruby/core/file.rb b/src/main/ruby/truffleruby/core/file.rb index 67f270a38200..735af9ae87f4 100644 --- a/src/main/ruby/truffleruby/core/file.rb +++ b/src/main/ruby/truffleruby/core/file.rb @@ -1161,13 +1161,12 @@ class << self def initialize(path_or_fd, mode = nil, perm = nil, **options) if Primitive.is_a?(path_or_fd, Integer) super(path_or_fd, mode, **options) - @path = nil else path = Truffle::Type.coerce_to_path path_or_fd nmode, _binary, _external, _internal, _autoclose, perm = Truffle::IOOperations.normalize_options(mode, perm, options) fd = IO.sysopen(path, nmode, perm) - @path = path + options[:path] = path super(fd, mode, **options) end end @@ -1208,9 +1207,6 @@ def stat Stat.fstat Primitive.io_fd(self) end - def path - @path.dup - end alias_method :to_path, :path def truncate(length) diff --git a/src/main/ruby/truffleruby/core/io.rb b/src/main/ruby/truffleruby/core/io.rb index 5a25c0338f6c..fadb8e3d41ee 100644 --- a/src/main/ruby/truffleruby/core/io.rb +++ b/src/main/ruby/truffleruby/core/io.rb @@ -846,7 +846,7 @@ def initialize(fd, mode = nil, **options) @external = nil @pid = nil - mode, binary, external, internal, autoclose_tmp, _perm = Truffle::IOOperations.normalize_options(mode, nil, options) + mode, binary, external, internal, autoclose_tmp, _perm, path = Truffle::IOOperations.normalize_options(mode, nil, options) fd = Truffle::Type.coerce_to(fd, Integer, :to_int) sync = fd == 2 # stderr is always unbuffered, see setvbuf(3) @@ -857,6 +857,7 @@ def initialize(fd, mode = nil, **options) @autoclose = autoclose_tmp @pipe = false + @path = path end ## @@ -1221,6 +1222,10 @@ def prepare_read_string(str) @lineno += 1 end + def path + @path.dup + end + ## # Return a string describing this IO object. def inspect diff --git a/src/main/ruby/truffleruby/core/truffle/io_operations.rb b/src/main/ruby/truffleruby/core/truffle/io_operations.rb index e49f89aa7421..18dd128821d8 100644 --- a/src/main/ruby/truffleruby/core/truffle/io_operations.rb +++ b/src/main/ruby/truffleruby/core/truffle/io_operations.rb @@ -543,10 +543,14 @@ def self.normalize_options(mode, perm, options, default_mode = nil) external, internal = encoding.split(':', 2) end end + + unless Primitive.nil? options[:path] + path = StringValue(options[:path]) + end end external = Encoding::BINARY if binary and !external and !internal perm ||= 0666 - [mode, binary, external, internal, autoclose, perm] + [mode, binary, external, internal, autoclose, perm, path] end end end