diff options
author | sorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-31 11:14:36 +0000 |
---|---|---|
committer | sorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-31 11:14:36 +0000 |
commit | 75cda5e22f6bc7ba6c91b6501d4233e782178a3a (patch) | |
tree | 64a4779a153f45831864a390ef84eb025fe1d4e4 /io.c | |
parent | 5f3c228f3975e4f4023168af2fba9f7434a904c5 (diff) |
File#path: Raise IOError when a file is O_TMPFILE
File#path for a file opened with O_TMPFILE has no meaning.
A filepath returned by this method isn't guarranteed about its accuracy,
but files opened with O_TMPFILE are known its recorded path has no
meaning. So let them not to return any pathname.
After a discussion in ruby-core, just returning Qnil makes guessing the
root cause difficult. Instead, this patch makes the method to raise an
error.
Other consideration is calling fnctl(2) on rb_file_path, but it adds a
overhead, and it's difficult to determine O_TMPFILE status after fd has
been closed.
[Feature #13568]
* io.c(rb_file_open_generic): Set Qnil to fptr->pathv when opening a
file using O_TMPFILE
* file.c(rb_file_path): Raise IOError when fptr->pathv is Qnil
* file.c(rb_file_path): [DOC] Update for the new behavior
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -5833,6 +5833,7 @@ static VALUE 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) { @@ -5848,8 +5849,15 @@ rb_file_open_generic(VALUE io, VALUE filename, int oflags, int fmode, 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); |