Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Mode definitions in Chef shouldn't be strings. #4

Merged
merged 1 commit into from Nov 20, 2012

Conversation

Projects
None yet
3 participants
Contributor

tas50 commented Nov 20, 2012

There's no need for this and it breaks Food Critic FC002. I've turned
them into 5 digit values

Mode definitions in Chef shouldn't be strings.
There's no need for this and it breaks Food Critic FC002.  I've turned
them into 5 digit values

cabeca added a commit that referenced this pull request Nov 20, 2012

Merge pull request #4 from tas50/master
Mode definitions in Chef shouldn't be strings.

@cabeca cabeca merged commit 40b8ae6 into cabeca:master Nov 20, 2012

Owner

cabeca commented Nov 20, 2012

Thanks for the patch. The documentation has both forms, but this one is probably cleaner.

antage commented on d358433 Aug 5, 2013

What is a reason to use 5 digit mode value instead of 4 digit value?

Owner

cabeca replied Aug 9, 2013

Hi,

This is to ensure an octal number is passed to mode as described in the documentation ( http://docs.opscode.com/resource_file.html )

UNIX- and Linux-based systems: The octal mode that is passed to chmod. If the value is specified as a quoted string, it will work exactly as if the chmod command was passed. If the value is specified as an integer, prepend a zero (0) to the value to ensure it is interpreted as an octal number. For example, to assign read, write, and execute rights for all users, use 0777 or '777'; for the same rights, plus the sticky bit, use 01777 or '1777'.

@cabeca I see. But in ruby 00644 == 0644. Single leading zero is enough for an octal number constant. What is meaning to write two leading zero? I think it's noisy and ... unusual.

Owner

cabeca replied Aug 9, 2013

This is for when you need to use the sticky bit. The first zero is there to signify an octal constant. The second zero is there to specify the sticky bit. Imagine you use the directory snippet with a single leading zero:

directory "/foo" do
   owner "root"
   group "root"
   mode 0755
   action :create
   recursive true
 end

later you change your mind and update the sticky bit:

directory "foo" do
   owner "root"
   group "root"
   mode 1755
   action :create
   recursive true
 end

You now have an error that's difficult to debug. So, to simplify things and to avoid these kind of pitfalls, the snippets have two leading zeroes.

At least that's how I see the motivation behind the two zeroes in this pull request :-) /cc @tas50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment