[macruby-changes] [4071] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue May 11 15:24:24 PDT 2010
Revision: 4071
http://trac.macosforge.org/projects/ruby/changeset/4071
Author: martinlagardette at apple.com
Date: 2010-05-11 15:24:22 -0700 (Tue, 11 May 2010)
Log Message:
-----------
Improve core/Dir pass rate
- Fix chdir specs (DirSpecs.pwd doesn't exist anymore, confirmed with newer RubySpec source)
- Implement Dir#home
- Fix Dir#chroot
- Fix rb_get_path_check to prefer #to_path before #to_str
Modified Paths:
--------------
MacRuby/trunk/dir.c
MacRuby/trunk/file.c
MacRuby/trunk/objc.m
MacRuby/trunk/spec/frozen/core/dir/chdir_spec.rb
Removed Paths:
-------------
MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chdir_tags.txt
MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chroot_tags.txt
MacRuby/trunk/spec/frozen/tags/macruby/core/dir/home_tags.txt
Modified: MacRuby/trunk/dir.c
===================================================================
--- MacRuby/trunk/dir.c 2010-05-11 21:26:06 UTC (rev 4070)
+++ MacRuby/trunk/dir.c 2010-05-11 22:24:22 UTC (rev 4071)
@@ -797,22 +797,17 @@
* platforms. On Unix systems, see <code>chroot(2)</code> for more
* information.
*/
-#if defined(HAVE_CHROOT) && !defined(__CHECKER__)
static VALUE
dir_s_chroot(VALUE dir, SEL sel, VALUE path)
{
- const char *path_cstr = RSTRING_PTR(path);
-
check_dirname(&path);
+ const char *path_cstr = RSTRING_PTR(path);
if (chroot(path_cstr) == -1)
rb_sys_fail(path_cstr);
return INT2FIX(0);
}
-#else
-# define dir_s_chroot rb_f_notimplement
-#endif
/*
* call-seq:
@@ -1838,7 +1833,30 @@
return Qfalse;
}
+VALUE rb_home_dir(VALUE user);
+
/*
+ * call-seq:
+ * Dir.home() => "/home/me"
+ * Dir.home("root") => "/root"
+ *
+ * Returns the home directory of the current user or the named user
+ * if given.
+ */
+static VALUE
+dir_s_home(VALUE obj, SEL sel, int argc, VALUE *argv)
+{
+ VALUE user;
+
+ rb_scan_args(argc, argv, "01", &user);
+ if (!NIL_P(user)) {
+ SafeStringValue(user);
+ //u = StringValueCStr(user);
+ }
+ return rb_home_dir(user);
+}
+
+/*
* Objects of class <code>Dir</code> are directory streams representing
* directories in the underlying file system. They provide a variety of
* ways to list directories and their contents. See also
@@ -1881,6 +1899,7 @@
rb_objc_define_method(*(VALUE *)rb_cDir, "rmdir", dir_s_rmdir, 1);
rb_objc_define_method(*(VALUE *)rb_cDir, "delete", dir_s_rmdir, 1);
rb_objc_define_method(*(VALUE *)rb_cDir, "unlink", dir_s_rmdir, 1);
+ rb_objc_define_method(*(VALUE *)rb_cDir, "home", dir_s_home, -1);
rb_objc_define_method(*(VALUE *)rb_cDir, "glob", dir_s_glob, -1);
rb_objc_define_method(*(VALUE *)rb_cDir, "[]", dir_s_aref, -1);
Modified: MacRuby/trunk/file.c
===================================================================
--- MacRuby/trunk/file.c 2010-05-11 21:26:06 UTC (rev 4070)
+++ MacRuby/trunk/file.c 2010-05-11 22:24:22 UTC (rev 4071)
@@ -99,21 +99,22 @@
static VALUE
rb_get_path_check(VALUE obj, int check)
{
+ VALUE tmp;
+
if (check) {
rb_check_safe_obj(obj);
}
- VALUE tmp = rb_check_string_type(obj);
- if (!NIL_P(tmp)) {
- goto exit;
- }
if (rb_vm_respond_to(obj, selToPath, true)) {
tmp = rb_vm_call(obj, selToPath, 0, NULL, false);
}
else {
- tmp = obj;
+ tmp = rb_check_string_type(obj);
+ if (NIL_P(tmp)) {
+ tmp = obj;
+ }
}
- exit:
+
StringValueCStr(tmp);
if (check && obj != tmp) {
rb_check_safe_obj(tmp);
Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m 2010-05-11 21:26:06 UTC (rev 4070)
+++ MacRuby/trunk/objc.m 2010-05-11 22:24:22 UTC (rev 4071)
@@ -202,6 +202,29 @@
}
VALUE
+rb_home_dir(VALUE user_name)
+{
+ NSString *user = nil;
+ NSString *home_dir = nil;
+
+ if (user_name != Qnil) {
+ user = (NSString *)user_name;
+ home_dir = NSHomeDirectoryForUser(user);
+ if (home_dir == nil) {
+ rb_raise(rb_eArgError, "user %s doesn't exist",
+ [user UTF8String]);
+ }
+ }
+ else {
+ home_dir = NSHomeDirectory();
+ if (home_dir == nil) {
+ return Qnil;
+ }
+ }
+ return rb_str_new2([home_dir fileSystemRepresentation]);
+}
+
+VALUE
rb_file_expand_path(VALUE fname, VALUE dname)
{
NSString *res = (NSString *)FilePathValue(fname);
Modified: MacRuby/trunk/spec/frozen/core/dir/chdir_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/dir/chdir_spec.rb 2010-05-11 21:26:06 UTC (rev 4070)
+++ MacRuby/trunk/spec/frozen/core/dir/chdir_spec.rb 2010-05-11 22:24:22 UTC (rev 4071)
@@ -21,16 +21,16 @@
it "defaults to $HOME with no arguments" do
if ENV['HOME']
Dir.chdir(ENV['HOME'])
- home = DirSpecs.pwd
+ home = Dir.pwd
Dir.chdir
- DirSpecs.pwd.should == home
+ Dir.pwd.should == home
end
end
it "changes to the specified directory" do
Dir.chdir DirSpecs.mock_dir
- DirSpecs.pwd.should == DirSpecs.mock_dir
+ Dir.pwd.should == DirSpecs.mock_dir
end
it "returns 0 when successfully changing directory" do
@@ -81,10 +81,10 @@
end
it "changes to the specified directory for the duration of the block" do
- ar = Dir.chdir(DirSpecs.mock_dir) { |dir| [dir, DirSpecs.pwd] }
+ ar = Dir.chdir(DirSpecs.mock_dir) { |dir| [dir, Dir.pwd] }
ar.should == [DirSpecs.mock_dir, DirSpecs.mock_dir]
- DirSpecs.pwd.should == @original
+ Dir.pwd.should == @original
end
it "raises a SystemCallError if the directory does not exist" do
@@ -119,6 +119,6 @@
rescue StandardError
end
- DirSpecs.pwd.should == @original
+ Dir.pwd.should == @original
end
end
Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chdir_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chdir_tags.txt 2010-05-11 21:26:06 UTC (rev 4070)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chdir_tags.txt 2010-05-11 22:24:22 UTC (rev 4071)
@@ -1,5 +0,0 @@
-fails:Dir.chdir defaults to $HOME with no arguments
-fails:Dir.chdir changes to the specified directory
-fails:Dir.chdir changes to the specified directory for the duration of the block
-fails:Dir.chdir always returns to the original directory when given a block
-fails:Dir.chdir prefers #to_path over #to_str
Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chroot_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chroot_tags.txt 2010-05-11 21:26:06 UTC (rev 4070)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/dir/chroot_tags.txt 2010-05-11 22:24:22 UTC (rev 4071)
@@ -1 +0,0 @@
-critical:Dir.chroot as regular user calls #to_path on non-String argument
Deleted: MacRuby/trunk/spec/frozen/tags/macruby/core/dir/home_tags.txt
===================================================================
--- MacRuby/trunk/spec/frozen/tags/macruby/core/dir/home_tags.txt 2010-05-11 21:26:06 UTC (rev 4070)
+++ MacRuby/trunk/spec/frozen/tags/macruby/core/dir/home_tags.txt 2010-05-11 22:24:22 UTC (rev 4071)
@@ -1,3 +0,0 @@
-fails:Dir.home returns the current user's home directory as a string if called without arguments
-fails:Dir.home returns the named user's home directory as a string if called with an argument
-fails:Dir.home raises an ArgumentError if the named user doesn't exist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100511/10ad0d83/attachment-0001.html>
More information about the macruby-changes
mailing list