Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Merged
merged 1 commit into from over 2 years ago

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 November 17, 2011
Closed

Ticket/2.7.x/7274 #19

lib/puppet/type/file/mode.rb
... ...
@@ -73,6 +73,14 @@ module Puppet
73 73
 
74 74
       super
75 75
     end
  76
+
  77
+    def should_to_s(should_value)
  78
+      should_value.to_s.rjust(4,"0")
  79
+    end
  80
+
  81
+    def is_to_s(currentvalue)
  82
+      currentvalue.to_s.rjust(4,"0")
  83
+    end
2
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 November 17, 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
(#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 November 22, 2011
Josh Cooper joshcooper closed this November 22, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 18, 2011
(#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
This page is out of date. Refresh to see the latest.
9  lib/puppet/type/file/mode.rb
@@ -73,6 +73,13 @@ def retrieve
73 73
 
74 74
       super
75 75
     end
  76
+
  77
+    def should_to_s(should_value)
  78
+      should_value.rjust(4,"0")
  79
+    end
  80
+
  81
+    def is_to_s(currentvalue)
  82
+      currentvalue.rjust(4,"0")
  83
+    end
76 84
   end
77 85
 end
78  
-
36  spec/unit/type/file/mode_spec.rb
@@ -103,4 +103,40 @@
103 103
       mode.retrieve.should == '644'
104 104
     end
105 105
   end
  106
+
  107
+  describe '#should_to_s' do
  108
+    describe 'with a 3-digit mode' do
  109
+      it 'returns a 4-digit mode with a leading zero' do
  110
+        mode.should_to_s('755').should == '0755'
  111
+      end
  112
+    end
  113
+
  114
+    describe 'with a 4-digit mode' do
  115
+      it 'returns the 4-digit mode when the first digit is a zero' do
  116
+        mode.should_to_s('0755').should == '0755'
  117
+      end
  118
+
  119
+      it 'returns the 4-digit mode when the first digit is not a zero' do
  120
+        mode.should_to_s('1755').should == '1755'
  121
+      end
  122
+    end
  123
+  end
  124
+
  125
+  describe '#is_to_s' do
  126
+    describe 'with a 3-digit mode' do
  127
+      it 'returns a 4-digit mode with a leading zero' do
  128
+        mode.is_to_s('755').should == '0755'
  129
+      end
  130
+    end
  131
+
  132
+    describe 'with a 4-digit mode' do
  133
+      it 'returns the 4-digit mode when the first digit is a zero' do
  134
+        mode.is_to_s('0755').should == '0755'
  135
+      end
  136
+
  137
+      it 'returns the 4-digit mode when the first digit is not a zero' do
  138
+        mode.is_to_s('1755').should == '1755'
  139
+      end
  140
+    end
  141
+  end
106 142
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.