[macruby-changes] [2041] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 21 15:13:54 PDT 2009


Revision: 2041
          http://trac.macosforge.org/projects/ruby/changeset/2041
Author:   pthomson at apple.com
Date:     2009-07-21 15:13:52 -0700 (Tue, 21 Jul 2009)
Log Message:
-----------
Re-enabled File#ctime and File#mtime, wrote File#chmod, fixed File.chmod, and made them all pass the specs.

Modified Paths:
--------------
    MacRuby/branches/experimental/file.c

Removed Paths:
-------------
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/chmod_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/ctime_tags.txt
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/mtime_tags.txt

Modified: MacRuby/branches/experimental/file.c
===================================================================
--- MacRuby/branches/experimental/file.c	2009-07-21 21:45:50 UTC (rev 2040)
+++ MacRuby/branches/experimental/file.c	2009-07-21 22:13:52 UTC (rev 2041)
@@ -142,8 +142,13 @@
 
     rb_secure(4);
     for (i=0; i<RARRAY_LEN(vargs); i++) {
-	path = rb_get_path(RARRAY_AT(vargs, i));
-	(*func)(StringValueCStr(path), arg);
+		path = rb_check_string_type(RARRAY_AT(vargs, i));
+		if (NIL_P(path))
+		{
+			// should we check for to_path too? i find it to be a hideous idiom.
+			rb_raise(rb_eTypeError, "paths must be strings or coerceable into strings");
+		}
+		(*func)(StringValueCStr(path), arg);
     }
 
     return RARRAY_LEN(vargs);
@@ -1703,15 +1708,12 @@
 static VALUE
 rb_file_mtime(VALUE obj, SEL sel)
 {
-    //     rb_io_t *fptr;
-    //     struct stat st;
-    // 
-    //     GetOpenFile(obj, fptr);
-    //     if (fstat(fptr->fd, &st) == -1) {
-    // rb_sys_fail(fptr->path);
-    //     }
-    //     return stat_mtime(&st);
-    rb_notimplement();
+	struct stat st;
+    struct rb_io_t *io = ExtractIOStruct(obj);
+    if (fstat(io->fd, &st) == -1) {
+	rb_sys_fail(RSTRING_PTR(io->path));
+    }
+	return stat_mtime(&st);
 }
 
 /*
@@ -1750,15 +1752,12 @@
 static VALUE
 rb_file_ctime(VALUE obj, SEL sel)
 {
-    //     rb_io_t *fptr;
-    //     struct stat st;
-    // 
-    //     GetOpenFile(obj, fptr);
-    //     if (fstat(fptr->fd, &st) == -1) {
-    // rb_sys_fail(fptr->path);
-    //     }
-    //     return stat_ctime(&st);
-    rb_notimplement();
+	struct stat st;
+    struct rb_io_t *io = ExtractIOStruct(obj);
+    if (fstat(io->fd, &st) == -1) {
+	rb_sys_fail(RSTRING_PTR(io->path));
+    }
+	return stat_ctime(&st);
 }
 
 static void
@@ -1791,6 +1790,11 @@
 
     rb_secure(2);
     rb_scan_args(argc, argv, "1*", &vmode, &rest);
+	vmode = rb_check_to_integer(vmode, "to_int");
+	if (NIL_P(vmode))
+	{
+		rb_raise(rb_eTypeError, "chmod() takes a numeric argument");
+	}
     mode = NUM2INT(vmode);
 
     n = apply2files(chmod_internal, rest, &mode);
@@ -1813,24 +1817,18 @@
 static VALUE
 rb_file_chmod(VALUE obj, SEL sel, VALUE vmode)
 {
-//     rb_io_t *fptr;
-//     int mode;
-// 
-//     rb_secure(2);
-//     mode = NUM2INT(vmode);
-// 
-//     GetOpenFile(obj, fptr);
-// #ifdef HAVE_FCHMOD
-//     if (fchmod(fptr->fd, mode) == -1)
-//  rb_sys_fail(fptr->path);
-// #else
-//     if (!fptr->path) return Qnil;
-//     if (chmod(fptr->path, mode) == -1)
-//  rb_sys_fail(fptr->path);
-// #endif
-// 
-//     return INT2FIX(0);
-    rb_notimplement();
+	rb_secure(2);
+	rb_io_t *io = ExtractIOStruct(obj);
+	vmode = rb_check_to_integer(vmode, "to_int");
+	if (NIL_P(vmode))
+	{
+		rb_raise(rb_eTypeError, "chmod() takes a numeric argument");
+	}
+	if (fchmod(io->fd, FIX2INT(vmode)) == -1)
+	{
+		rb_sys_fail(RSTRING_PTR(io->path));
+	}
+	return INT2FIX(0);
 }
 
 #if defined(HAVE_LCHMOD)

Deleted: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/chmod_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/chmod_tags.txt	2009-07-21 21:45:50 UTC (rev 2040)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/chmod_tags.txt	2009-07-21 22:13:52 UTC (rev 2041)
@@ -1,10 +0,0 @@
-fails:File#chmod returns 0 if successful
-fails:File#chmod always succeeds with any numeric values
-fails:File#chmod invokes to_int on non-integer argument
-fails:File#chmod with '0222' makes file writable but not readable or executable
-fails:File#chmod with '0444' makes file readable but not writable or executable
-fails:File#chmod with '0666' makes file readable and writable but not executable
-fails:File#chmod with '0111' makes file executable but not readable or writable
-fails:File#chmod modifies the permission bits of the files specified
-fails:File.chmod invokes to_int on non-integer argument
-fails:File.chmod invokes to_str on non-string file names

Deleted: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/ctime_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/ctime_tags.txt	2009-07-21 21:45:50 UTC (rev 2040)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/ctime_tags.txt	2009-07-21 22:13:52 UTC (rev 2041)
@@ -1 +0,0 @@
-fails:File#ctime Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself).

Deleted: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/mtime_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/mtime_tags.txt	2009-07-21 21:45:50 UTC (rev 2040)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/mtime_tags.txt	2009-07-21 22:13:52 UTC (rev 2041)
@@ -1 +0,0 @@
-fails:File#mtime returns the modification Time of the file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090721/982ea003/attachment.html>


More information about the macruby-changes mailing list