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

ruby-changes:4096

From: ko1@a...
Date: Sun, 24 Feb 2008 03:53:23 +0900 (JST)
Subject: [ruby-changes:4096] nobu - Ruby:r15586 (trunk, ruby_1_8): * util.c (valid_filename): use O_EXCL to get rid of clobbering

nobu	2008-02-24 03:53:00 +0900 (Sun, 24 Feb 2008)

  New Revision: 15586

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/util.c
    branches/ruby_1_8/version.h
    trunk/ChangeLog
    trunk/util.c
    trunk/version.h

  Log:
    * util.c (valid_filename): use O_EXCL to get rid of clobbering
      existing files in race conditions.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=15586&r2=15585&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=15586&r2=15585&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15586&r2=15585&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/util.c?r1=15586&r2=15585&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/util.c?r1=15586&r2=15585&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/version.h?r1=15586&r2=15585&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15585)
+++ ChangeLog	(revision 15586)
@@ -1,3 +1,8 @@
+Sun Feb 24 03:52:58 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* util.c (valid_filename): use O_EXCL to get rid of clobbering
+	  existing files in race conditions.
+
 Sat Feb 23 21:36:13 2008  NAKAMURA Usaku  <usa@r...>
 
 	* ext/win32ole/win32ole.c (ole_init_cp): should return value.
Index: util.c
===================================================================
--- util.c	(revision 15585)
+++ util.c	(revision 15586)
@@ -346,22 +346,18 @@
     int fd;
 
     /*
-    // if the file exists, then it's a valid filename!
-    */
-
-    if (_access(s, 0) == 0) {
-	return 1;
-    }
-
-    /*
     // It doesn't exist, so see if we can open it.
     */
 
-    if ((fd = _open(s, O_CREAT, 0666)) >= 0) {
+    if ((fd = _open(s, O_CREAT|O_EXCL, 0666)) >= 0) {
 	_close(fd);
 	_unlink(s);	/* don't leave it laying around */
 	return 1;
     }
+    else if (errno == EEXIST) {
+	/* if the file exists, then it's a valid filename! */
+	return 1;
+    }
     return 0;
 }
 #endif
Index: version.h
===================================================================
--- version.h	(revision 15585)
+++ version.h	(revision 15586)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.9.0"
-#define RUBY_RELEASE_DATE "2008-02-23"
+#define RUBY_RELEASE_DATE "2008-02-24"
 #define RUBY_VERSION_CODE 190
-#define RUBY_RELEASE_CODE 20080223
+#define RUBY_RELEASE_CODE 20080224
 #define RUBY_PATCHLEVEL 0
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 0
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 23
+#define RUBY_RELEASE_DAY 24
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8/util.c
===================================================================
--- ruby_1_8/util.c	(revision 15585)
+++ ruby_1_8/util.c	(revision 15586)
@@ -234,22 +234,18 @@
     int fd;
 
     /*
-    // if the file exists, then it's a valid filename!
-    */
-
-    if (_access(s, 0) == 0) {
-	return 1;
-    }
-
-    /*
     // It doesn't exist, so see if we can open it.
     */
 
-    if ((fd = _open(s, O_CREAT, 0666)) >= 0) {
+    if ((fd = _open(s, O_CREAT|O_EXCL, 0666)) >= 0) {
 	_close(fd);
 	_unlink(s);	/* don't leave it laying around */
 	return 1;
     }
+    else if (errno == EEXIST) {
+	/* if the file exists, then it's a valid filename! */
+	return 1;
+    }
     return 0;
 }
 #endif
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 15585)
+++ ruby_1_8/ChangeLog	(revision 15586)
@@ -1,3 +1,8 @@
+Sun Feb 24 03:52:58 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* util.c (valid_filename): use O_EXCL to get rid of clobbering
+	  existing files in race conditions.
+
 Fri Feb 22 19:50:19 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* bignum.c (BIGZEROP): fix for longer Bignum zeros.  [ruby-Bugs-17454]
Index: ruby_1_8/version.h
===================================================================
--- ruby_1_8/version.h	(revision 15585)
+++ ruby_1_8/version.h	(revision 15586)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2008-02-22"
+#define RUBY_RELEASE_DATE "2008-02-24"
 #define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20080222
+#define RUBY_RELEASE_CODE 20080224
 #define RUBY_PATCHLEVEL 5000
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 6
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 22
+#define RUBY_RELEASE_DAY 24
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];

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

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