1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c, internal.h (rb_io_flush_raw): new function to select calling

fsync() (on Windows).

* io.c (rb_io_flush_raw): use above function.

* file.c (rb_file_truncate): use above function.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2013-08-15 11:53:41 +00:00
parent 12a0b0c8f4
commit d6af2a2b21
5 changed files with 44 additions and 24 deletions

View file

@ -1,3 +1,12 @@
Thu Aug 15 20:51:29 2013 NAKAMURA Usaku <usa@ruby-lang.org>
* io.c, internal.h (rb_io_flush_raw): new function to select calling
fsync() (on Windows).
* io.c (rb_io_flush_raw): use above function.
* file.c (rb_file_truncate): use above function.
Thu Aug 15 18:39:31 2013 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (clock_gettime): improve precision when freq is less

4
file.c
View file

@ -4244,7 +4244,11 @@ rb_file_truncate(VALUE obj, VALUE len)
if (!(fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "not opened for writing");
}
#ifndef _WIN32
rb_io_flush(obj);
#else
rb_io_flush_raw(obj, 0);
#endif
#ifdef HAVE_FTRUNCATE
if (ftruncate(fptr->fd, pos) < 0)
rb_sys_fail_path(fptr->pathv);

View file

@ -283,6 +283,7 @@ void ruby_set_inplace_mode(const char *);
ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
void rb_stdio_set_default_encoding(void);
void rb_write_error_str(VALUE mesg);
VALUE rb_io_flush_raw(VALUE, int);
/* iseq.c */
VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase);

52
io.c
View file

@ -1464,6 +1464,34 @@ nogvl_fsync(void *ptr)
}
#endif
VALUE
rb_io_flush_raw(VALUE io, int sync)
{
rb_io_t *fptr;
if (!RB_TYPE_P(io, T_FILE)) {
return rb_funcall(io, id_flush, 0);
}
io = GetWriteIO(io);
GetOpenFile(io, fptr);
if (fptr->mode & FMODE_WRITABLE) {
if (io_fflush(fptr) < 0)
rb_sys_fail(0);
#ifdef _WIN32
if (sync && GetFileType((HANDLE)rb_w32_get_osfhandle(fptr->fd)) == FILE_TYPE_DISK) {
rb_thread_io_blocking_region(nogvl_fsync, fptr, fptr->fd);
}
#endif
}
if (fptr->mode & FMODE_READABLE) {
io_unread(fptr);
}
return io;
}
/*
* call-seq:
* ios.flush -> ios
@ -1483,29 +1511,7 @@ nogvl_fsync(void *ptr)
VALUE
rb_io_flush(VALUE io)
{
rb_io_t *fptr;
if (!RB_TYPE_P(io, T_FILE)) {
return rb_funcall(io, id_flush, 0);
}
io = GetWriteIO(io);
GetOpenFile(io, fptr);
if (fptr->mode & FMODE_WRITABLE) {
if (io_fflush(fptr) < 0)
rb_sys_fail(0);
#ifdef _WIN32
if (GetFileType((HANDLE)rb_w32_get_osfhandle(fptr->fd)) == FILE_TYPE_DISK) {
rb_thread_io_blocking_region(nogvl_fsync, fptr, fptr->fd);
}
#endif
}
if (fptr->mode & FMODE_READABLE) {
io_unread(fptr);
}
return io;
return rb_io_flush_raw(io, 1);
}
/*

View file

@ -120,7 +120,7 @@ class PStoreTest < Test::Unit::TestCase
def test_pstore_files_are_accessed_as_binary_files
bug5311 = '[ruby-core:39503]'
n = 128
assert_in_out_err(["-Eutf-8:utf-8", "-rpstore", "-", @pstore_file], <<-SRC, [bug5311], [], bug5311, timeout: 60)
assert_in_out_err(["-Eutf-8:utf-8", "-rpstore", "-", @pstore_file], <<-SRC, [bug5311], [], bug5311, timeout: 15)
@pstore = PStore.new(ARGV[0])
(1..#{n}).each do |i|
@pstore.transaction {@pstore["Key\#{i}"] = "value \#{i}"}