Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with File/FileUtils.chmod Ruby

Tags:

ruby

I'm running into a rather odd problem with Ruby and File.chmod (same problem exists with FileUtils.chmod.

Here is what I am doing for a test case:

File.chmod(1777, "testfile")

But once I have done that, I get this as a permission set:

--wxrwS--t

This problem only exists when using the *nix 4 digit permission sets. I googled it, but didn't get anything of value. When the permission set is 0777 it assigns properly, but anything higher than 0 for the first digit will mess up the permissions pretty bad.

Anybody have any tips?

I know I could make a system call to do what I want, but I'm sure it is something simple that I'm missing.

like image 826
Eugene Avatar asked Dec 18 '22 02:12

Eugene


1 Answers

01777 will work. In ruby a leading zero in an integer literal specifies that it's written in octal notation and file permissions are usually written as octal numbers.

like image 138
sepp2k Avatar answered Dec 31 '22 19:12

sepp2k