filegroup
-
This function’s solution assumes a Unix-like operating system.
The
filegroupfunction in PHP returns the group ID owning a file.PHP
$gid = filegroup('/path/to/foobar'); print $gid; //=> 501
You can retrieve a file’s group ID in Ruby by calling
File.stat. It will return aFile::Statinstance that contains agidattribute.Ruby
stat = File.stat('/path/to/foobar') p stat.gid #=> 501
Resolving the Group Name
If you also need the name from the group ID, you can use PHP’s
posix_getgrgidfunction to retrieve this information and more.PHP
$gid = filegroup('/path/to/foobar'); $info = posix_getgrgid($gid); print $info['name']; //=> "herbert"
The
Etcmodule from the Ruby Standard Library provides agetgrgidmethod. It returns aStructwith attributes similar to the keys of the associative array returned by PHP’sposix_getgrgid.Ruby
require 'etc' gid = File.stat('/path/to/foobar').gid info = Etc.getgrgid(gid) p info.name #=> "herbert"
Comparing to the Current Process
Ruby’s
Fileclass provides an additional method,grpowned?, that tests if the effective group ID of the current process is the group ID of a file.Ruby
File.grpowned?('/path/to/foobar') #=> true
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

