Forum: Ruby File.addmod?

Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-10-09 21:29
I'm familiar with
File.chmod 0777 filename

however, anybody know the equivalent to "chmod u+r filename" from the
command line--but in ruby?
Thanks!
-r
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-10-09 22:47
(Received via mailing list)
On Oct 9, 2009, at 3:29 PM, Roger Pack wrote:

> I'm familiar with
> File.chmod 0777 filename
>
> however, anybody know the equivalent to "chmod u+r filename" from the
> command line--but in ruby?
> Thanks!
> -r
> --
> Posted via http://www.ruby-forum.com/.
>
File.class_eval do
   def self.addmod(flags, filename)
     themode=stat(filename).mode | flags
     chmod(themode, filename)
   end
end

Although there's no error checking and the return value could probably
be something better (like themode).

So after defining that, your 'u+r' would be:
   File.addmod(0200, 'filename')


-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-10-10 00:04
> File.class_eval do
>    def self.addmod(flags, filename)
>      themode=stat(filename).mode | flags
>      chmod(themode, filename)
>    end
> end
>
> Although there's no error checking and the return value could probably
> be something better (like themode).
>
> So after defining that, your 'u+r' would be:
>    File.addmod(0200, 'filename')

Much thanks.
-r
79f9616c279f40ef953f366dcfe38dc8?d=identicon&s=25 Suraj Kurapati (sunaku)
on 2009-10-10 09:25
Roger Pack wrote:
> the equivalent to "chmod u+r filename" [...] in ruby?

I filed a feature request for symbolic mode ('u+r') support
in FileUtils::chmod() and FileUtils::chmod_R() methods here:

  http://redmine.ruby-lang.org/issues/show/2190

Cheers.
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-10-10 23:09
> I filed a feature request for symbolic mode ('u+r') support
> in FileUtils::chmod() and FileUtils::chmod_R() methods here:
>
>   http://redmine.ruby-lang.org/issues/show/2190
>
> Cheers.

Thanks for doing that.
-r
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.