Question: ruby vs. ksh


(David Douthitt) #1

David Douthitt
CUNA & Affiliates
UNIX Systems Administrator
ddouthitt@cuna.coop

tim@vegeta.ath.cx 7/1/02 7:30PM >>>
David Douthitt graced us by uttering:
PPS: How do I do

chown -R user:grp dir

in Ruby?

File::chown

can also be used for chgrp(1) operations.

Basically, many shell commands can be replaced by the use
of commands in the Kernel, File, or Dir modules.

Except that wasn’t the point (chgrp, that is). I hadn’t thought about it, but I figure that part would be easy. The important (harder?) question is the ‘-R’ option: recursing through the entire directory and all subdirectories underneath it, changing the ownership for all files.


(Massimiliano Mirra) #2

This pops out every now and then in different contexts: recursive
delete, recursive copy, (and now) recursive chowning…

I wonder whether a unified implementation would be possible, e.g.:

recurse(dir) do |item|
File.delete(item)
end

Find.find is very similar, though it first visits directories and then
their content (preventing to delete directories), and does not change
the current dir.

Ideas?

Massimiliano

···

On Tue, Jul 02, 2002 at 10:08:25PM +0900, David Douthitt wrote:

chown -R user:grp dir

Except that wasn’t the point (chgrp, that is). I hadn’t thought
about it, but I figure that part would be easy. The important
(harder?) question is the ‘-R’ option: recursing through the entire
directory and all subdirectories underneath it, changing the
ownership for all files.


(HAL 9000) #3

If that is the case, it should be possible to steal the
code from Find and make a minor change in it.

It might also be good to have an iterator that only
visited directories. But I haven’t thought that through.

Hal Fulton

···

----- Original Message -----
From: “Massimiliano Mirra” list@NOSPAMchromatic-harp.com.web-hosting.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 02, 2002 12:19 PM
Subject: Re: Question: ruby vs. ksh

recurse(dir) do |item|
File.delete(item)
end

Find.find is very similar, though it first visits directories and then
their content (preventing to delete directories), and does not change
the current dir.

Ideas?