Skip to content

Tickets/2.7.x/7274 always output 4 digit modes #226

Merged
merged 1 commit into from Nov 22, 2011

3 participants

@jhelwig
jhelwig commented Nov 18, 2011

When updating file mode, output 4 digit file mode instead of omitting
the leading 0, i.e. 0755 instead of 755. This fully represents the
file mode, and lessens the likelihood of someone incorrectly setting
the mode on a file by copy/pasting the incomplete mode specification.

Signed-off-by: Nan Liu nan@puppetlabs.com
Signed-off-by: Jacob Helwig jacob@puppetlabs.com

@jhelwig jhelwig referenced this pull request Nov 18, 2011
Closed

Ticket/2.7.x/7274 #19

@nicklewis nicklewis and 1 other commented on an outdated diff Nov 18, 2011
lib/puppet/type/file/mode.rb
@@ -73,6 +73,14 @@ module Puppet
super
end
+
+ def should_to_s(should_value)
+ should_value.to_s.rjust(4,"0")
+ end
+
+ def is_to_s(currentvalue)
+ currentvalue.to_s.rjust(4,"0")
+ end
@nicklewis
Puppet member
nicklewis added a note Nov 18, 2011

Are should_value and currentvalue strings or numbers in these methods? If they're strings, the to_s is unnecessary. If they're numbers, this does the wrong thing (it would print decimal) and the tests aren't realistic.

But given that the method is called should_to_s, though, I would guess the default just calls to_s, and since we currently do print octal, it must be that the argument is a string, and so to_s is unnecessary here.

@jhelwig
jhelwig added a note Nov 18, 2011

You're right that it's no longer necessary. It was needed (though wrong) before puppet resource was fixed to always create file resources using strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jacob Helwig (#7274) Output 4-digit file modes in File type
When updating file mode, output 4 digit file mode instead of omitting
the leading 0, i.e. 0755 instead of 755.  This fully represents the
file mode, and lessens the likelihood of someone incorrectly setting
the mode on a file by copy/pasting the incomplete mode specification.

Signed-off-by: Nan Liu <nan@puppetlabs.com>
Signed-off-by: Jacob Helwig <jacob@puppetlabs.com>
c804346
@jhelwig
jhelwig commented Nov 18, 2011

Updated to remove the unnecessary to_s calls.

@jhelwig
jhelwig commented Nov 19, 2011

This can't go in until after #196

@joshcooper joshcooper merged commit c804346 into puppetlabs:2.7.x Nov 22, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.