how to set permission '777' to dir?

A

Albert Schlef

Pat said:
hello, I've some question when I want to create new folder with
permission '777'.

I use following code

Code:
FileUtils.mkdir 'tmp', :mode => 0777

and the result is in the picture. it show me '775' what's wrong with
this code?

That's because, on POSIX systems, the permissions of a new
file/directory are set to what you asked for (0777 in your case) minus
something called umask. Google for "umask" to learn about it.

If you really want 0777, do File.chmod() (or FileUtils.chmod()) after
creating the file.
 
P

Pat Kiatchaipipat

I try FileUtils.chmod() after create new file but it still has permision
'775' :'(
 
B

Brian Candler

Try running this script:

begin
Dir.mkdir("footst")
puts File.stat("footst").mode.to_s(8)
File.chmod(0777, "footst")
puts File.stat("footst").mode.to_s(8)
ensure
Dir.rmdir("footst")
end

For me (under Linux) it shows:
40755
40777

Does it not for you?

The alternative solution (which is probably not threadsafe) is to modify
umask, like this:

begin
old_umask = File.umask
File.umask 0
Dir.mkdir("footst")
puts File.stat("footst").mode.to_s(8)
Dir.rmdir("footst")
ensure
File.umask old_umask
end
 
P

Pat Kiatchaipipat

oh I try in Linux with the same code it's
40755
40777

what's wrong with window7? it has another way to do it :'(
 
A

Albert Schlef

Pat said:
oh I try in Linux with the same code it's
40755
40777

what's wrong with windows7? it has another way to do it :'(

You mean to say that Windows 7 has the unixy owner/group/world
permissions for files? Wow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top