ruby-changes:23627
From: nobu <ko1@a...>
Date: Fri, 18 May 2012 00:05:12 +0900 (JST)
Subject: [ruby-changes:23627] nobu:r35678 (ruby_1_9_3): merge revision(s) 35109,35110,35651: [Backport #6385]
nobu 2012-05-18 00:04:57 +0900 (Fri, 18 May 2012) New Revision: 35678 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35678 Log: merge revision(s) 35109,35110,35651: [Backport #6385] * win32/win32.c (rb_w32_fstat, rb_w32_fstati64): convert FILETIME to time_t directly, not to be affected by TZ unnecessarily. * win32/win32.c (unixtime_to_filetime): convert time_t to FILETIME simply. Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/include/ruby/win32.h branches/ruby_1_9_3/test/ruby/test_file.rb branches/ruby_1_9_3/version.h branches/ruby_1_9_3/win32/win32.c Index: ruby_1_9_3/include/ruby/win32.h =================================================================== --- ruby_1_9_3/include/ruby/win32.h (revision 35677) +++ ruby_1_9_3/include/ruby/win32.h (revision 35678) @@ -149,6 +149,7 @@ #define getppid() rb_w32_getppid() #define sleep(x) rb_w32_Sleep((x)*1000) #define Sleep(msec) (void)rb_w32_Sleep(msec) +#define fstati64(fd,st) rb_w32_fstati64(fd,st) #ifdef __BORLANDC__ #define creat(p, m) _creat(p, m) #define eof() _eof() @@ -157,7 +158,6 @@ #define tell(h) _tell(h) #define _open _sopen #define sopen _sopen -#define _fstati64(fd,st) rb_w32_fstati64(fd,st) #undef fopen #define fopen(p, m) rb_w32_fopen(p, m) #undef fdopen @@ -184,7 +184,7 @@ #if SIZEOF_OFF_T == 8 #define off_t __int64 #define stat stati64 -#define fstat(fd,st) _fstati64(fd,st) +#define fstat(fd,st) fstati64(fd,st) #if defined(__BORLANDC__) #define stati64(path, st) rb_w32_stati64(path, st) #elif !defined(_MSC_VER) || RT_VER < 80 @@ -195,7 +195,6 @@ #else #define stati64 _stat64 #define _stat64(path, st) rb_w32_stati64(path, st) -#define _fstati64 _fstat64 #endif #else #define stat(path,st) rb_w32_stat(path,st) @@ -305,9 +304,9 @@ extern int rb_w32_access(const char *, int); extern int rb_w32_uaccess(const char *, int); extern char rb_w32_fd_is_text(int); +extern int rb_w32_fstati64(int, struct stati64 *); #ifdef __BORLANDC__ -extern int rb_w32_fstati64(int, struct stati64 *); extern off_t _lseeki64(int, off_t, int); extern FILE *rb_w32_fopen(const char *, const char *); extern FILE *rb_w32_fdopen(int, const char *); Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 35677) +++ ruby_1_9_3/ChangeLog (revision 35678) @@ -1,3 +1,11 @@ +Fri May 18 00:04:53 2012 Nobuyoshi Nakada <nobu@r...> + + * win32/win32.c (rb_w32_fstat, rb_w32_fstati64): convert FILETIME + to time_t directly, not to be affected by TZ unnecessarily. + + * win32/win32.c (unixtime_to_filetime): convert time_t to FILETIME + simply. + Wed May 16 01:07:46 2012 Aaron Patterson <aaron@t...> * ext/digest/md5/extconf.rb: use pkg_config for openssl so that Index: ruby_1_9_3/win32/win32.c =================================================================== --- ruby_1_9_3/win32/win32.c (revision 35677) +++ ruby_1_9_3/win32/win32.c (revision 35678) @@ -4131,7 +4131,8 @@ (dest).st_ctime = (src).st_ctime; \ } while (0) -#ifdef __BORLANDC__ +static time_t filetime_to_unixtime(const FILETIME *ft); + #undef fstat int rb_w32_fstat(int fd, struct stat *st) @@ -4140,10 +4141,18 @@ int ret = fstat(fd, st); if (ret) return ret; +#ifdef __BORLANDC__ st->st_mode &= ~(S_IWGRP | S_IWOTH); - if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info) && - !(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) { - st->st_mode |= S_IWUSR; +#endif + if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) { +#ifdef __BORLANDC__ + if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) { + st->st_mode |= S_IWUSR; + } +#endif + st->st_atime = filetime_to_unixtime(&info.ftLastAccessTime); + st->st_mtime = filetime_to_unixtime(&info.ftLastWriteTime); + st->st_ctime = filetime_to_unixtime(&info.ftCreationTime); } return ret; } @@ -4156,17 +4165,23 @@ int ret = fstat(fd, &tmp); if (ret) return ret; +#ifdef __BORLANDC__ tmp.st_mode &= ~(S_IWGRP | S_IWOTH); +#endif COPY_STAT(tmp, *st, +); if (GetFileInformationByHandle((HANDLE)_get_osfhandle(fd), &info)) { +#ifdef __BORLANDC__ if (!(info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) { st->st_mode |= S_IWUSR; } +#endif st->st_size = ((__int64)info.nFileSizeHigh << 32) | info.nFileSizeLow; + st->st_atime = filetime_to_unixtime(&info.ftLastAccessTime); + st->st_mtime = filetime_to_unixtime(&info.ftLastWriteTime); + st->st_ctime = filetime_to_unixtime(&info.ftCreationTime); } return ret; } -#endif static time_t filetime_to_unixtime(const FILETIME *ft) @@ -5456,27 +5471,11 @@ static int unixtime_to_filetime(time_t time, FILETIME *ft) { - struct tm *tm; - SYSTEMTIME st; - FILETIME lt; + ULARGE_INTEGER tmp; - tm = localtime(&time); - if (!tm) { - return -1; - } - st.wYear = tm->tm_year + 1900; - st.wMonth = tm->tm_mon + 1; - st.wDayOfWeek = tm->tm_wday; - st.wDay = tm->tm_mday; - st.wHour = tm->tm_hour; - st.wMinute = tm->tm_min; - st.wSecond = tm->tm_sec; - st.wMilliseconds = 0; - if (!SystemTimeToFileTime(&st, <) || - !LocalFileTimeToFileTime(<, ft)) { - errno = map_errno(GetLastError()); - return -1; - } + tmp.QuadPart = ((LONG_LONG)time + (LONG_LONG)((1970-1601)*365.2425) * 24 * 60 * 60) * 10 * 1000 * 1000; + ft->dwLowDateTime = tmp.LowPart; + ft->dwHighDateTime = tmp.HighPart; return 0; } Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 35677) +++ ruby_1_9_3/version.h (revision 35678) @@ -1,10 +1,10 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 215 +#define RUBY_PATCHLEVEL 216 -#define RUBY_RELEASE_DATE "2012-05-16" +#define RUBY_RELEASE_DATE "2012-05-18" #define RUBY_RELEASE_YEAR 2012 #define RUBY_RELEASE_MONTH 5 -#define RUBY_RELEASE_DAY 16 +#define RUBY_RELEASE_DAY 18 #include "ruby/version.h" Index: ruby_1_9_3/test/ruby/test_file.rb =================================================================== --- ruby_1_9_3/test/ruby/test_file.rb (revision 35677) +++ ruby_1_9_3/test/ruby/test_file.rb (revision 35678) @@ -181,6 +181,26 @@ } end + def test_utime + bug6385 = '[ruby-core:44776]' + + mod_time_contents = Time.at 1306527039 + + file = Tempfile.new("utime") + file.close + path = file.path + + File.utime(File.atime(path), mod_time_contents, path) + stats = File.stat(path) + + file.open + file_mtime = file.mtime + file.close(true) + + assert_equal(mod_time_contents, file_mtime, bug6385) + assert_equal(mod_time_contents, stats.mtime, bug6385) + end + def test_chmod_m17n bug5671 = '[ruby-dev:44898]' Dir.mktmpdir('test-file-chmod-m17n-') do |tmpdir| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/