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
[/code]
and the result is in the picture. it show me '775' what's wrong with
this code?
Attachments:
http://www.ruby-forum.com/attachment/4476/err1.jpg
···
--
Posted via http://www.ruby-forum.com/.
Pat Kiatchaipipat wrote:
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
[/code]
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.
···
--
Posted via http://www.ruby-forum.com/\.
I try FileUtils.chmod() after create new file but it still has permision
'775'
···
--
Posted via http://www.ruby-forum.com/.
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
···
--
Posted via http://www.ruby-forum.com/.
it's show me
40755
40755
??
···
--
Posted via http://www.ruby-forum.com/.
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
···
--
Posted via http://www.ruby-forum.com/.
Pat Kiatchaipipat wrote:
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.
···
--
Posted via http://www.ruby-forum.com/\.