E F van de Laar
3/2/2005 9:25:00 AM
Brian Candler wrote:
> Just a simple suggestion, but it would be really nice if File.chown could
> take user and group *names* as well as numeric IDs.
>
> It would simplify this:
>
> File.chown(Etc.getpwnam("foo").uid, Etc.getgrnam("bar").gid, filename)
>
> to this:
>
> File.chown("foo", "bar", filename)
>
> Seem reasonable?? There doesn't seem to be a chown in fileutils.rb either.
I've written some code like this before too and your suggestion is a
good one IMHO. The relevant code is implemented in file.c. I'm not sure
if it would be a good idea to pollute this code with these kind of
lookups though. Another thing to consider is how other platforms handle
this, i.e. Windows.
Does this work on win32? Etc.getpwnam("Administrator").uid
In the mean time maybe something like this...
def File.my_chown(o, g, file)
case o
when Numeric
uid = o
when String
require 'Etc'
uid = Etc.getpwnam(o).uid
end
case g
when Numeric
gid = g
when String
require 'Etc'
gid = Etc.getgrnam(g).gid
end
File.chown(uid, gid, file)
end
Cheers,
Emiel
--
Emiel van de Laar