Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

3 participants

Jacob Helwig Nick Lewis Josh Cooper
Jacob Helwig

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

Jacob Helwig jhelwig referenced this pull request
Closed

Ticket/2.7.x/7274 #19

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
Nick Lewis Owner

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.

Jacob Helwig
jhelwig added a note

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
Jacob Helwig

Updated to remove the unnecessary to_s calls.

Jacob Helwig

This can't go in until after #196

Josh Cooper joshcooper merged commit c804346 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 18, 2011
  1. (#7274) Output 4-digit file modes in File type

    Jacob Helwig authored
    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>
This page is out of date. Refresh to see the latest.
Showing with 44 additions and 1 deletion.
  1. +8 −1 lib/puppet/type/file/mode.rb
  2. +36 −0 spec/unit/type/file/mode_spec.rb
9 lib/puppet/type/file/mode.rb
View
@@ -73,6 +73,13 @@ def retrieve
super
end
+
+ def should_to_s(should_value)
+ should_value.rjust(4,"0")
+ end
+
+ def is_to_s(currentvalue)
+ currentvalue.rjust(4,"0")
+ end
end
end
-
36 spec/unit/type/file/mode_spec.rb
View
@@ -103,4 +103,40 @@
mode.retrieve.should == '644'
end
end
+
+ describe '#should_to_s' do
+ describe 'with a 3-digit mode' do
+ it 'returns a 4-digit mode with a leading zero' do
+ mode.should_to_s('755').should == '0755'
+ end
+ end
+
+ describe 'with a 4-digit mode' do
+ it 'returns the 4-digit mode when the first digit is a zero' do
+ mode.should_to_s('0755').should == '0755'
+ end
+
+ it 'returns the 4-digit mode when the first digit is not a zero' do
+ mode.should_to_s('1755').should == '1755'
+ end
+ end
+ end
+
+ describe '#is_to_s' do
+ describe 'with a 3-digit mode' do
+ it 'returns a 4-digit mode with a leading zero' do
+ mode.is_to_s('755').should == '0755'
+ end
+ end
+
+ describe 'with a 4-digit mode' do
+ it 'returns the 4-digit mode when the first digit is a zero' do
+ mode.is_to_s('0755').should == '0755'
+ end
+
+ it 'returns the 4-digit mode when the first digit is not a zero' do
+ mode.is_to_s('1755').should == '1755'
+ end
+ end
+ end
end
Something went wrong with that request. Please try again.