[前][次][番号順一覧][スレッド一覧]

ruby-changes:38155

From: akr <ko1@a...>
Date: Sat, 11 Apr 2015 23:34:37 +0900 (JST)
Subject: [ruby-changes:38155] akr:r50236 (trunk): * file.c (rb_f_test): Consider nsec for "=", "<" and ">" for "test"

akr	2015-04-11 23:34:26 +0900 (Sat, 11 Apr 2015)

  New Revision: 50236

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50236

  Log:
    * file.c (rb_f_test): Consider nsec for "=", "<" and ">" for "test"

  Modified files:
    trunk/ChangeLog
    trunk/file.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50235)
+++ ChangeLog	(revision 50236)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 11 23:33:22 2015  Tanaka Akira  <akr@f...>
+
+	* file.c (rb_f_test): Consider nsec for "=", "<" and ">" for "test"
+	  method.
+
 Sat Apr 11 23:26:05 2015  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* tool/rbinstall.rb: support destdir for native extention gem.
Index: file.c
===================================================================
--- file.c	(revision 50235)
+++ file.c	(revision 50236)
@@ -4829,22 +4829,28 @@ rb_f_test(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/file.c#L4829
 
     if (strchr("=<>", cmd)) {
 	struct stat st1, st2;
+        struct timespec t1, t2;
 
 	CHECK(2);
 	if (rb_stat(argv[1], &st1) < 0) return Qfalse;
 	if (rb_stat(argv[2], &st2) < 0) return Qfalse;
 
+        t1 = stat_mtimespec(&st1);
+        t2 = stat_mtimespec(&st2);
+
 	switch (cmd) {
 	  case '=':
-	    if (st1.st_mtime == st2.st_mtime) return Qtrue;
+	    if (t1.tv_sec == t2.tv_sec && t1.tv_nsec == t2.tv_nsec) return Qtrue;
 	    return Qfalse;
 
 	  case '>':
-	    if (st1.st_mtime > st2.st_mtime) return Qtrue;
+	    if (t1.tv_sec > t2.tv_sec) return Qtrue;
+	    if (t1.tv_sec == t2.tv_sec && t1.tv_nsec > t2.tv_nsec) return Qtrue;
 	    return Qfalse;
 
 	  case '<':
-	    if (st1.st_mtime < st2.st_mtime) return Qtrue;
+	    if (t1.tv_sec < t2.tv_sec) return Qtrue;
+	    if (t1.tv_sec == t2.tv_sec && t1.tv_nsec < t2.tv_nsec) return Qtrue;
 	    return Qfalse;
 	}
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]