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

ruby-changes:6738

From: nobu <ko1@a...>
Date: Tue, 29 Jul 2008 05:38:31 +0900 (JST)
Subject: [ruby-changes:6738] Ruby:r18253 (trunk, ruby_1_8): * file.c (rb_find_file_ext, rb_find_file): converts Windows style path

nobu	2008-07-29 05:38:04 +0900 (Tue, 29 Jul 2008)

  New Revision: 18253

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

  Log:
    * file.c (rb_find_file_ext, rb_find_file): converts Windows style path
      to Cygwin path.  [ruby-dev:35647]

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/file.c
    trunk/ChangeLog
    trunk/file.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18252)
+++ ChangeLog	(revision 18253)
@@ -1,3 +1,8 @@
+Tue Jul 29 05:37:53 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_find_file_ext, rb_find_file): converts Windows style path
+	  to Cygwin path.  [ruby-dev:35647]
+
 Tue Jul 29 02:39:46 2008  NARUSE, Yui  <naruse@r...>
 
 	* math.c (math_atanh): raise EDOM on FreeBSD when atanh(1).
Index: file.c
===================================================================
--- file.c	(revision 18252)
+++ file.c	(revision 18253)
@@ -4447,6 +4447,14 @@
     return eaccess(path, R_OK) == 0;
 }
 
+static int
+is_explicit_relative(const char *path)
+{
+    if (*path++ != '.') return 0;
+    if (*path == '.') path++;
+    return isdirsep(*path);
+}
+
 VALUE rb_get_load_path(void);
 
 int
@@ -4468,15 +4476,18 @@
 	*filep = fname;
     }
 
-    if (is_absolute_path(f)) {
+    if (is_absolute_path(f) || is_explicit_relative(f)) {
+	fname = rb_str_dup(*filep);
+	fnlen = RSTRING_LEN(fname);
 	for (i=0; ext[i]; i++) {
-	    fname = rb_str_dup(*filep);
 	    rb_str_cat2(fname, ext[i]);
-	    OBJ_FREEZE(fname);
 	    if (file_load_ok(StringValueCStr(fname))) {
+		if (!is_absolute_path(f)) fname = rb_file_expand_path(fname, Qnil);
+		OBJ_FREEZE(fname);
 		*filep = fname;
 		return i+1;
 	    }
+	    rb_str_set_len(fname, fnlen);
 	}
 	return 0;
     }
@@ -4534,12 +4545,13 @@
     }
 #endif
 
-    if (is_absolute_path(f)) {
+    if (is_absolute_path(f) || is_explicit_relative(f)) {
 	if (rb_safe_level() >= 1 && !fpath_check(f)) {
 	    rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
 	}
-	if (file_load_ok(f)) return path;
-	return 0;
+	if (!file_load_ok(f)) return 0;
+	if (!is_absolute_path(f)) path = rb_file_expand_path(path, Qnil);
+	return path;
     }
 
     if (rb_safe_level() >= 4) {
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 18252)
+++ ruby_1_8/ChangeLog	(revision 18253)
@@ -1,3 +1,8 @@
+Tue Jul 29 05:37:53 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (rb_find_file_ext, rb_find_file): converts Windows style path
+	  to Cygwin path.  [ruby-dev:35647]
+
 Mon Jul 28 20:46:39 2008  Kouhei Sutou  <kou@c...>
 
 	* test/rss/: use PNG instead of zlib as binary data. [ruby-dev:35666]
Index: ruby_1_8/file.c
===================================================================
--- ruby_1_8/file.c	(revision 18252)
+++ ruby_1_8/file.c	(revision 18253)
@@ -4388,6 +4388,15 @@
     return 1;
 }
 
+static int
+is_explicit_relative(path)
+    const char *path;
+{
+    if (*path++ != '.') return 0;
+    if (*path == '.') path++;
+    return isdirsep(*path);
+}
+
 extern VALUE rb_load_path;
 
 int
@@ -4399,6 +4408,8 @@
     VALUE fname, tmp;
     long i, j, fnlen;
 
+    if (!ext[0]) return 0;
+
     if (f[0] == '~') {
 	fname = rb_file_expand_path(*filep, Qnil);
 	if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) {
@@ -4409,15 +4420,18 @@
 	*filep = fname;
     }
 
-    if (is_absolute_path(f)) {
+    if (is_absolute_path(f) || is_explicit_relative(f)) {
+	fname = rb_str_dup(*filep);
+	fnlen = RSTRING_LEN(fname);
 	for (i=0; ext[i]; i++) {
-	    fname = rb_str_dup(*filep);
 	    rb_str_cat2(fname, ext[i]);
-	    OBJ_FREEZE(fname);
 	    if (file_load_ok(StringValueCStr(fname))) {
+		if (!is_absolute_path(f)) fname = rb_file_expand_path(fname, Qnil);
+		OBJ_FREEZE(fname);
 		*filep = fname;
 		return i+1;
 	    }
+	    rb_str_set_len(fname, fnlen);
 	}
 	return 0;
     }
@@ -4474,11 +4488,13 @@
     }
 #endif
 
-    if (is_absolute_path(f)) {
+    if (is_absolute_path(f) || is_explicit_relative(f)) {
 	if (rb_safe_level() >= 1 && !fpath_check(f)) {
 	    rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
 	}
-	if (file_load_ok(f)) return path;
+	if (!file_load_ok(f)) return 0;
+	if (!is_absolute_path(f)) path = rb_file_expand_path(path, Qnil);
+	return path;
 	return 0;
     }
 

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

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