Forum: Ruby File.stat.mode not same mode as File.stat.inspect ??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8e30b8d93c6e4357f60fc250cc9e0631?d=identicon&s=25 Zach Buckholz (Guest)
on 2006-05-25 19:37
(Received via mailing list)
I am working on a little ruby script to check file stats and I am
getting a weird mask when I query the mode directly. I am also looking
at stat.2 (man 2 stat) and the bits just are not adding up to give me 8.

The proper mode is 0100644 but when I print @mode = fileObj.stat.mode I
get 33188

print "-----\n", fileObj.stat.inspect, "\n-----\n"
-----
#<File::Stat dev=0x6809, ino=19, mode=0100644, nlink=1, uid=506,
gid=501, rdev=0x0, size=50, blksize=4096, blocks=8, atime=Tue May 23
16:19:47 MST 2006, mtime=Tue May 23 16:19:47 MST 2006, ctime=Tue May 23
16:19:47 MST 2006>
-----
print fileObj.stat.mode
33188     <---- Value that's confusing me
print fileObj.stat.uid
501
print fileObj.stat.gid
506



Can anyone clarify what I am doing wrong?


Thanks
Zach
B33ea5c12d767bfd1253940a960274f5?d=identicon&s=25 Tim Hunter (timhunter)
on 2006-05-25 19:45
Zach Buckholz wrote:
> I am working on a little ruby script to check file stats and I am
> getting a weird mask when I query the mode directly. I am also looking
> at stat.2 (man 2 stat) and the bits just are not adding up to give me 8.
>
> The proper mode is 0100644 but when I print @mode = fileObj.stat.mode I
> get 33188
>

0100644 octal == 33188 decimal
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 Ryan Leavengood (Guest)
on 2006-05-25 19:50
(Received via mailing list)
On 5/25/06, Zach Buckholz <zach.buckholz@apollogrp.edu> wrote:
>
> I am working on a little ruby script to check file stats and I am
> getting a weird mask when I query the mode directly. I am also looking
> at stat.2 (man 2 stat) and the bits just are not adding up to give me 8.
>
> The proper mode is 0100644 but when I print @mode = fileObj.stat.mode I
> get 33188

You are displaying the mode in decimal when it should be octal to
match what you think it should be:

irb(main):001:0> '%07o' % 33188
=> "0100644

Ryan
This topic is locked and can not be replied to.