Skip to content

Commit 958aa07

Browse files
committed
addressed review
addressed review Promoted File#path to IO#path, added path: optional param to IO#new
1 parent b4a05b5 commit 958aa07

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

spec/tags/core/io/path_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/ruby/truffleruby/core/file.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
class File < IO
3838
include Enumerable
3939

40-
class FileError < Exception; end # rubocop:disable Lint/InheritException
40+
class FileError < RuntimeError; end
41+
4142
class NoFileError < FileError; end
43+
4244
class UnableToStat < FileError; end
45+
4346
class PermissionError < FileError; end
4447

4548
# these will be necessary when we run on Windows
@@ -1161,13 +1164,12 @@ class << self
11611164
def initialize(path_or_fd, mode = nil, perm = nil, **options)
11621165
if Primitive.is_a?(path_or_fd, Integer)
11631166
super(path_or_fd, mode, **options)
1164-
@path = nil
11651167
else
11661168
path = Truffle::Type.coerce_to_path path_or_fd
11671169
nmode, _binary, _external, _internal, _autoclose, perm = Truffle::IOOperations.normalize_options(mode, perm, options)
11681170
fd = IO.sysopen(path, nmode, perm)
11691171

1170-
@path = path
1172+
options[:path] = path
11711173
super(fd, mode, **options)
11721174
end
11731175
end
@@ -1208,10 +1210,6 @@ def stat
12081210
Stat.fstat Primitive.io_fd(self)
12091211
end
12101212

1211-
def path
1212-
@path.dup
1213-
end
1214-
alias_method :to_path, :path
12151213

12161214
def truncate(length)
12171215
length = Truffle::Type.coerce_to length, Integer, :to_int

src/main/ruby/truffleruby/core/io.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def initialize(fd, mode = nil, **options)
846846
@external = nil
847847
@pid = nil
848848

849-
mode, binary, external, internal, autoclose_tmp, _perm = Truffle::IOOperations.normalize_options(mode, nil, options)
849+
mode, binary, external, internal, autoclose_tmp, _perm, path = Truffle::IOOperations.normalize_options(mode, nil, options)
850850

851851
fd = Truffle::Type.coerce_to(fd, Integer, :to_int)
852852
sync = fd == 2 # stderr is always unbuffered, see setvbuf(3)
@@ -857,6 +857,7 @@ def initialize(fd, mode = nil, **options)
857857

858858
@autoclose = autoclose_tmp
859859
@pipe = false
860+
@path = path
860861
end
861862

862863
##
@@ -1221,6 +1222,12 @@ def prepare_read_string(str)
12211222
@lineno += 1
12221223
end
12231224

1225+
def path
1226+
@path.dup
1227+
end
1228+
1229+
alias_method :to_path, :path
1230+
12241231
##
12251232
# Return a string describing this IO object.
12261233
def inspect

src/main/ruby/truffleruby/core/truffle/io_operations.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,14 @@ def self.normalize_options(mode, perm, options, default_mode = nil)
543543
external, internal = encoding.split(':', 2)
544544
end
545545
end
546+
547+
unless Primitive.nil? options[:path]
548+
path = StringValue(options[:path])
549+
end
546550
end
547551
external = Encoding::BINARY if binary and !external and !internal
548552
perm ||= 0666
549-
[mode, binary, external, internal, autoclose, perm]
553+
[mode, binary, external, internal, autoclose, perm, path]
550554
end
551555
end
552556
end

0 commit comments

Comments
 (0)