Skip to content

Commit

Permalink
IO#dup will copy a file path.
Browse files Browse the repository at this point in the history
Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

io = STDOUT.dup
assert_equal("#<IO:<STDOUT>>", io.inspect)

io = File.open("/tmp/foo", "w")
io2 = io.dup
assert_equal("#<File:/tmp/foo>", io2.inspect)
io.close

r, w = IO.pipe
io = r.dup
assert_match(/#<IO:fd \d+>/, io.inspect)

f = File.open("/tmp/foo", "w")
w.reopen(f)
assert_equal("/tmp/foo", w.path)

puts :ok
}}}
  • Loading branch information
Watson1978 committed May 30, 2011
1 parent 02a3563 commit af05b3f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions io.c
Expand Up @@ -2735,6 +2735,9 @@ io_replace_streams(int fd, rb_io_t *dest, rb_io_t *origin)
dest->buf = NULL;
}
dest->buf_offset = origin->buf_offset;
if (origin->path) {
GC_WB(&dest->path, rb_str_dup(origin->path));
}
}

static VALUE
Expand Down Expand Up @@ -2770,10 +2773,6 @@ io_reopen(VALUE io, VALUE nfile)
}
io_replace_streams(fd, io_s, other);

if (other->path) {
GC_WB(&io_s->path, rb_str_dup(other->path));
}

*(VALUE *)io = *(VALUE *)nfile;

return io;
Expand Down

0 comments on commit af05b3f

Please sign in to comment.