[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6290] Re: lchown()/etc. and Unix syscall completeness

From: Mathieu Bouchard <matju@...>
Date: 2000-11-12 06:58:56 UTC
List: ruby-talk #6290
> there.  But other useful ones are missing.  File.chmod and File.chown are 
> there, but the l-prefixed syscalls like File.lchmod and File.lchown are
> missing.

patch below.

(note: lchmod() doesn't seem to be a Posix call; plus, i've never seen a
symlink that's not precisely 0777)

----------------8<--------cut-here--------8<----------------

Index: file.c
===================================================================
RCS file: /home/cvs/ruby/file.c,v
retrieving revision 1.40
diff -u -r1.40 file.c
--- file.c	2000/10/17 18:13:55	1.40
+++ file.c	2000/11/12 06:51:31
@@ -954,6 +954,7 @@
 
 struct chown_args {
     int owner, group;
+    int symlink_p;
 };
 
 static void
@@ -961,7 +962,11 @@
     const char *path;
     struct chown_args *args;
 {
-    if (chown(path, args->owner, args->group) < 0)
+    int result = args->symlink_p ?
+	lchown(path, args->owner, args->group) :
+	chown (path, args->owner, args->group);
+
+    if (result < 0)
 	rb_sys_fail(path);
 }
 
@@ -972,25 +977,27 @@
 {
     VALUE o, g, rest;
     struct chown_args arg;
-    int n;
-
     rb_secure(2);
     rb_scan_args(argc, argv, "2*", &o, &g, &rest);
-    if (NIL_P(o)) {
-	arg.owner = -1;
-    }
-    else {
-	arg.owner = NUM2INT(o);
-    }
-    if (NIL_P(g)) {
-	arg.group = -1;
-    }
-    else {
-	arg.group = NUM2INT(g);
-    }
+    arg.owner = NIL_P(o) ? -1 : NUM2INT(o);
+    arg.group = NIL_P(g) ? -1 : NUM2INT(g);
+    arg.symlink_p = 0;
+    return INT2FIX(apply2files(chown_internal, rest, &arg));
+}
 
-    n = apply2files(chown_internal, rest, &arg);
-    return INT2FIX(n);
+static VALUE
+rb_file_s_lchown(argc, argv)
+    int argc;
+    VALUE *argv;
+{
+    VALUE o, g, rest;
+    struct chown_args arg;
+    rb_secure(2);
+    rb_scan_args(argc, argv, "2*", &o, &g, &rest);
+    arg.owner = NIL_P(o) ? -1 : NUM2INT(o);
+    arg.group = NIL_P(g) ? -1 : NUM2INT(g);
+    arg.symlink_p = 1;
+    return INT2FIX(apply2files(chown_internal, rest, &arg));
 }
 
 static VALUE
@@ -2202,6 +2209,7 @@
     rb_define_singleton_method(rb_cFile, "utime", rb_file_s_utime, -1);
     rb_define_singleton_method(rb_cFile, "chmod", rb_file_s_chmod, -1);
     rb_define_singleton_method(rb_cFile, "chown", rb_file_s_chown, -1);
+    rb_define_singleton_method(rb_cFile, "lchown",rb_file_s_lchown,-1);
 
     rb_define_singleton_method(rb_cFile, "link", rb_file_s_link, 2);
     rb_define_singleton_method(rb_cFile, "symlink", rb_file_s_symlink, 2);


In This Thread