Prob with File.open and perms


#1

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 ???


#2

From: Une Bévue [mailto:removed_email_address@domain.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


#3

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.


#4

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:removed_email_address@domain.invalid]

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:removed_email_address@domain.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


#5

Nobuyoshi N. removed_email_address@domain.invalid 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 :wink:


#6

Peña, Botp removed_email_address@domain.invalid wrote:

sorry for the noise,

no prob at all, u’ve tried to answer something !