Forum: Ruby prob with File.open and perms

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.
672d693d2b8d408648f664b93d84e8e9?d=identicon&s=25 unknown (Guest)
on 2007-01-27 07:55
(Received via mailing list)
if i use :
File.open('a_file',File::WRONLY|File::TRUNC|File::CREAT) do |f|
  f.print 'something'
end

the 'a_file' i get has the following perms :
-rw-r--r--

which correspond to 644 (right?)
generally it's OK with those perms.

however if i rewrite the three lines above specifying the perms as 644 :
File.open('a_file',File::WRONLY|File::TRUNC|File::CREAT,644) do |f|
 f.print 'something'
end

i get the following perms :
--w----r--

and then i can't do even a cat upon this file )))

is it my missunderstanding of File.open or a bugg ???
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2007-01-27 08:13
(Received via mailing list)
From: Une Bévue [mailto:unbewusst.sein@google.com.invalid]
# i get the following perms :
# --w----r--
#

Hi Une,

it works for me.

#----------
root@pc4all:~# cat test3.rb
File.open('a_file',File::WRONLY|File::TRUNC|File::CREAT,644) do |f|
  f.print 'something else'
end
root@pc4all:~# ruby test3.rb

root@pc4all:~# ll a_file
-rw-r--r-- 1 root root 14 Jan 27 15:07 a_file

root@pc4all:~# ruby -v; uname -an
ruby 1.8.5 (2006-12-21 patchlevel 5000) [i686-linux]
Linux pc4all 2.6.15-27-686 #1 SMP PREEMPT Fri Dec 8 18:00:07 UTC 2006
i686 GNU/Linux
#----------

kind regards -botp
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (Guest)
on 2007-01-27 08:37
(Received via mailing list)
Hi,

At Sat, 27 Jan 2007 15:55:08 +0900,
Une Bévue wrote in [ruby-talk:236374]:
> which correspond to 644 (right?)

That is octal.

> however if i rewrite the three lines above specifying the perms as 644 :
> File.open('a_file',File::WRONLY|File::TRUNC|File::CREAT,644) do |f|
                                                          ^^^
Use 0644.
672d693d2b8d408648f664b93d84e8e9?d=identicon&s=25 unknown (Guest)
on 2007-01-27 09:01
(Received via mailing list)
Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:

> That is octal.
>
> > however if i rewrite the three lines above specifying the perms as 644 :
> > File.open('a_file',File::WRONLY|File::TRUNC|File::CREAT,644) do |f|
>                                                           ^^^
> Use 0644.

Fine thanks for the trick ;-)
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2007-01-27 09:18
(Received via mailing list)
pls ignore my post below. it's terrible. i should have deleted the
outputted file before running the program again.

nobu's post is the_ answer.

In this regard, may i suggest a feature for documenting methods

from File.new(filename [, mode [, perm]]) => file

to File.new(filename               => String
            [, mode = File::WRONLY => Integer in File IO
            [, perm = 0644         => Integer in octal form]]
            )
            => file in IO

or something like that. A quick glance, we'd know more about the
parameters..

sorry for the noise,
kind regards -botp


# -----Original Message-----
# From: Peña, Botp [mailto:botp@delmonte-phil.com]
# Sent: Saturday, January 27, 2007 3:14 PM
# To: ruby-talk ML
# Subject: Re: prob with File.open and perms
#
# From: Une Bévue [mailto:unbewusst.sein@google.com.invalid]
# # i get the following perms :
# # --w----r--
# #
#
# Hi Une,
#
# it works for me.
#
# #----------
# root@pc4all:~# cat test3.rb
# File.open('a_file',File::WRONLY|File::TRUNC|File::CREAT,644) do |f|
#   f.print 'something else'
# end
# root@pc4all:~# ruby test3.rb
#
# root@pc4all:~# ll a_file
# -rw-r--r-- 1 root root 14 Jan 27 15:07 a_file
#
# root@pc4all:~# ruby -v; uname -an
# ruby 1.8.5 (2006-12-21 patchlevel 5000) [i686-linux]
# Linux pc4all 2.6.15-27-686 #1 SMP PREEMPT Fri Dec 8 18:00:07
# UTC 2006 i686 GNU/Linux
# #----------
#
# kind regards -botp
#
#
#
#
#
672d693d2b8d408648f664b93d84e8e9?d=identicon&s=25 unknown (Guest)
on 2007-01-27 10:01
(Received via mailing list)
Peña, Botp <botp@delmonte-phil.com> wrote:

> sorry for the noise,

no prob at all, u've tried to answer something !
This topic is locked and can not be replied to.