From: eregontp@... Date: 2016-04-22T11:42:01+00:00 Subject: [ruby-core:75128] [Ruby trunk Bug#12307][Rejected] File.new and File.open change permissions even if the file exists on Windows Issue #12307 has been updated by Benoit Daloze. Status changed from Open to Rejected Thank you for the C example and explanation! So indeed the behavior of MSVCRT contradicts its description: "[...] If the file already exists, pmode is ignored." but it's not in practice. So it's indeed a bug either in MSVCRT documentation or implementation, right? > BTW, this problem occurs only when opening an existing file with "w" and mode 04xx. > I think this is not a real use case, and this problem may not causes any real problem. I am not sure, maybe it can be used to create a read-only file but still allow to write the initial contents ("w" counts for permissions to write for the fd, 04xx is only for further open calls): `File.open("abc", "w", 0444) { |f| f.write "abcd" }` It's probably not very frequent in Ruby code, indeed. You are the maintainer, so this is your decision :) If somebody has this problem in a real scenario, please reopen this bug or comment. ---------------------------------------- Bug #12307: File.new and File.open change permissions even if the file exists on Windows https://bugs.ruby-lang.org/issues/12307#change-58260 * Author: Benoit Daloze * Status: Rejected * Priority: Normal * Assignee: * ruby -v: ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32] * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- For instance: ~~~ # New file File.open("abc", "w", 0666) { |f| puts f.stat.mode.to_s(8) # => 100666, OK } # File exists File.open("abc", "w", 0466) { |f| puts f.stat.mode.to_s(8) # => 100444, BUG } ~~~ So the mode of the file was changed even though the file already exists. This is inconsistent with the behavior on other platforms such as UNIX which only consider mode for new files. open(2) is fairly clear about this on Linux and OS X: "if neither O_CREAT nor O_TMPFILE is specified, then mode is ignored". -- https://bugs.ruby-lang.org/ Unsubscribe: