Project

General

Profile

Feature #11258

add 'x' mode character for O_EXCL

Added by cremno (cremno phobia) about 4 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:69568]

Description

I just saw #11253 which contains:

But some modes has only integer form like O_CLOEXEC, O_EXCL.

However C11 added x to open a file for exclusive access. It's also supported by Python.

http://port70.net/~nsz/c/c11/n1570.html#7.21.5.3p5
https://docs.python.org/3.3/library/functions.html#open


Files

excl_mode_v1.diff (3.46 KB) excl_mode_v1.diff cremno (cremno phobia), 06/16/2015 06:47 PM
excl_mode_v2.diff (4.41 KB) excl_mode_v2.diff cremno (cremno phobia), 07/29/2015 06:35 PM

Related issues

Has duplicate Ruby master - Feature #14007: open mode 'x' to raise error if file existsClosedActions

Associated revisions

Revision 842b7359
Added by kazu about 1 year ago

add 'x' mode character for O_EXCL

[Feature #11258]
Patch by cremno (cremno phobia)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 64245
Added by znz (Kazuhiro NISHIYAMA) about 1 year ago

add 'x' mode character for O_EXCL

[Feature #11258]
Patch by cremno (cremno phobia)

Revision 64245
Added by kazu about 1 year ago

add 'x' mode character for O_EXCL

[Feature #11258]
Patch by cremno (cremno phobia)

History

Updated by cremno (cremno phobia) about 4 years ago

Here is a preliminary patch that passes make test-all (except for some RubyGems/SSL tests) on a glibc-based Linux (but I think some less common code might not work anymore on Windows and other platforms that don't implement x but validate the mode string). Also rb_io_oflags_modestr() didn't differentiate between w+ and r+ before - was that intended?

Updated by normalperson (Eric Wong) about 4 years ago

cremno@mail.ru wrote:

Issue #11258 has been updated by cremno phobia.

File excl_mode_v1.diff added

Here is a preliminary patch that passes make test-all (except for
some RubyGems/SSL tests) on a glibc-based Linux (but I think some less
common code might not work anymore on Windows and other platforms that
don't implement x but validate the mode string).

Haven't tested, but I like this feature for consistency with glibc
and Python.

Also rb_io_oflags_modestr() didn't differentiate between w+ and r+
before - was that intended?

I hope not, but it may also be too late to change without breaking
existing code and causing major data loss...

Updated by normalperson (Eric Wong) about 4 years ago

Eric Wong normalperson@yhbt.net wrote:

cremno@mail.ru wrote:

Also rb_io_oflags_modestr() didn't differentiate between w+ and r+
before - was that intended?

I hope not, but it may also be too late to change without breaking
existing code and causing major data loss...

Scratch that. I misremembered what rb_io_oflags_modestr did :x

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

+#define MODE_BINARY_EXCL(a,b,c,d) \
+ ((oflags & O_EXCL) ? MODE_BINARY(d, c) : MODE_BINARY(b, a))

'a', 'b' and 'c', 'd' are inverted?

Updated by matz (Yukihiro Matsumoto) about 4 years ago

It looks good to me.

Matz.

Updated by cremno (cremno phobia) about 4 years ago

Nobuyoshi Nakada wrote:

+#define MODE_BINARY_EXCL(a,b,c,d) \
+ ((oflags & O_EXCL) ? MODE_BINARY(d, c) : MODE_BINARY(b, a))

'a', 'b' and 'c', 'd' are inverted?

Yes, MODE_BINARY confused me (it uses it arguments in reverse order). I think MODE_BINARY_EXCL is a bad idea anyway. In V2 an ArgumentError is raised by rb_io_oflags_modestr() when O_EXCL is set. This also affects the related flags: File::EXCL feature. $stdout.reopen('stdout', 'w', flags: File::EXCL) does now raise as it should since freopen() might not support x which could cause the truncation of an existing file! That might not be the best solution though.

V2 also contains documentation and a news entry.

#7

Updated by shyouhei (Shyouhei Urabe) almost 2 years ago

  • Has duplicate Feature #14007: open mode 'x' to raise error if file exists added

Updated by ko1 (Koichi Sasada) about 1 year ago

  • Assignee set to znz (Kazuhiro NISHIYAMA)
#9

Updated by znz (Kazuhiro NISHIYAMA) about 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r64245.


add 'x' mode character for O_EXCL

[Feature #11258]
Patch by cremno (cremno phobia)

Also available in: Atom PDF