Project

General

Profile

Feature #13568 » 0001-File-path-Raise-IOError-when-a-file-is-O_TMPFILE.patch

sorah (Sorah Fukumori), 08/31/2017 07:02 AM

View differences:

file.c
* not normalize the name.
*
* The pathname may not point the file corresponding to <i>file</i>.
* e.g. file has been moved, deleted, or created with <code>File::TMPFILE</code> option.
* For instance, pathname becomes inaccurate when file has been moved or deleted.
*
* This method raises <code>IOError</code> for a <i>file</i> created using
* <code>File::Constants::TMPFILE</code> because they don't have a pathname.
*
* File.new("testfile").path #=> "testfile"
* File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx"
......
fptr = RFILE(rb_io_taint_check(obj))->fptr;
rb_io_check_initialized(fptr);
if (NIL_P(fptr->pathv)) return Qnil;
if (NIL_P(fptr->pathv)) {
rb_raise(rb_eIOError, "File is unnamed (TMPFILE?)");
}
return rb_obj_taint(rb_str_dup(fptr->pathv));
}
io.c
rb_file_open_generic(VALUE io, VALUE filename, int oflags, int fmode,
const convconfig_t *convconfig, mode_t perm)
{
VALUE pathv;
rb_io_t *fptr;
convconfig_t cc;
if (!convconfig) {
......
MakeOpenFile(io, fptr);
fptr->mode = fmode;
fptr->encs = *convconfig;
fptr->pathv = rb_str_new_frozen(filename);
fptr->fd = rb_sysopen(fptr->pathv, oflags, perm);
pathv = rb_str_new_frozen(filename);
#ifdef O_TMPFILE
if (!(oflags & O_TMPFILE)) {
fptr->pathv = pathv;
}
#else
fptr->pathv = pathv;
#endif
fptr->fd = rb_sysopen(pathv, oflags, perm);
io_check_tty(fptr);
if (fmode & FMODE_SETENC_BY_BOM) io_set_encoding_by_bom(io);
test/ruby/test_file.rb
assert_file.not_exist?(path)
end
end
def test_open_tempfile_path
Dir.mktmpdir(__method__.to_s) do |tmpdir|
File.open(tmpdir, File::RDWR | File::TMPFILE) do |io|
io.write "foo"
io.flush
assert_equal 3, io.size
assert_raise(IOError) { io.path }
end
end
end if File::Constants.const_defined?(:TMPFILE)
end
(2-2/2)