* file.c (File::SHARE_DELETE): new flag to be able to delete opened file

on Windows.

* include/win32/win32.c (O_SHARE_DELETE): new pseudo file mode flag.

* win32/win32.c (rb_w32_{w,}open): support above flag.  [EXPERIMENTAL]

* NEWS: mention about this feature.
  [Feature #11218] [ruby-dev:49022]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2015-06-12 12:14:06 +00:00
Родитель d6b8acacf6
Коммит 2bc2802096
6 изменённых файлов: 43 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,15 @@
Fri Jun 12 21:01:44 2015 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (File::SHARE_DELETE): new flag to be able to delete opened file
on Windows.
* include/win32/win32.c (O_SHARE_DELETE): new pseudo file mode flag.
* win32/win32.c (rb_w32_{w,}open): support above flag. [EXPERIMENTAL]
* NEWS: mention about this feature.
[Feature #11218] [ruby-dev:49022]
Fri Jun 12 18:21:45 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* ChangeLog: added missing commit message.

6
NEWS
Просмотреть файл

@ -24,6 +24,12 @@ with all sufficient information, see the ChangeLog file.
* Numeric#positive? and Numeric#negative? are added, which return
true when the receiver is positive and negative respectively.
* IO
* new mode flag File::SHARE_DELETE is available.
this flag means to permit deleting opened file on Windows, but currently
this affect only files opened as binary. [Feature #11218]
=== Core classes compatibility issues (excluding feature bug fixes)
* Array

5
file.c
Просмотреть файл

@ -5982,6 +5982,11 @@ Init_File(void)
#endif
/* disable line code conversion */
rb_define_const(rb_mFConst, "BINARY", INT2FIX(O_BINARY));
#ifndef O_SHARE_DELETE
# define O_SHARE_DELETE 0
#endif
/* can delete opened file */
rb_define_const(rb_mFConst, "SHARE_DELETE", INT2FIX(O_SHARE_DELETE));
#ifdef O_SYNC
/* any write operation perform synchronously */
rb_define_const(rb_mFConst, "SYNC", INT2FIX(O_SYNC));

Просмотреть файл

@ -124,6 +124,8 @@ typedef unsigned int uintptr_t;
#define WNOHANG -1
#define O_SHARE_DELETE 0x80000000 /* for rb_w32_open(), rb_w32_wopen() */
typedef int clockid_t;
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1

Просмотреть файл

@ -375,6 +375,19 @@ class TestFile < Test::Unit::TestCase
}
end
def test_file_share_delete
Dir.mktmpdir(__method__.to_s) do |tmpdir|
tmp = File.join(tmpdir, 'x')
File.open(tmp, mode: IO::WRONLY | IO::CREAT | IO::BINARY | IO::SHARE_DELETE) do |f|
assert_file.exist?(tmp)
assert_nothing_raised do
File.unlink(tmp)
end
end
assert_file.not_exist?(tmp)
end
end
def test_conflicting_encodings
Dir.mktmpdir(__method__.to_s) do |tmpdir|
tmp = File.join(tmpdir, 'x')

Просмотреть файл

@ -5775,6 +5775,7 @@ rb_w32_open(const char *file, int oflag, ...)
va_end(arg);
if ((oflag & O_TEXT) || !(oflag & O_BINARY)) {
oflag &= ~O_SHARE_DELETE;
ret = _open(file, oflag, pmode);
if (ret == -1 && errno == EACCES) check_if_dir(file);
return ret;
@ -5797,7 +5798,10 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...)
DWORD attr = FILE_ATTRIBUTE_NORMAL;
SECURITY_ATTRIBUTES sec;
HANDLE h;
int share_delete;
share_delete = oflag & O_SHARE_DELETE ? FILE_SHARE_DELETE : 0;
oflag &= ~O_SHARE_DELETE;
if ((oflag & O_TEXT) || !(oflag & O_BINARY)) {
va_list arg;
int pmode;
@ -5919,8 +5923,7 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...)
_set_osfhnd(fd, (intptr_t)INVALID_HANDLE_VALUE);
_set_osflags(fd, 0);
h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec,
create, attr, NULL);
h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE | share_delete, &sec, create, attr, NULL);
if (h == INVALID_HANDLE_VALUE) {
DWORD e = GetLastError();
if (e != ERROR_ACCESS_DENIED || !check_if_wdir(file))