Eugene
Eugene

Reputation: 4879

Problem with File/FileUtils.chmod 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.

Upvotes: 5

Views: 2037

Answers (1)

sepp2k
sepp2k

Reputation: 370092

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.

Upvotes: 13

Related Questions