summaryrefslogtreecommitdiff
path: root/lib/puppet/type/file_line.rb
diff options
context:
space:
mode:
authorGeoff Williams <GeoffWilliams@users.noreply.github.com>2017-03-14 01:24:36 +1100
committerPaula McMaw <paula@puppet.com>2017-03-13 14:24:36 +0000
commit46e3a2349e9eef4001db8be9581fae9dfbccaf14 (patch)
tree999af0329383b541ec2cd782cdaa47ede5f32791 /lib/puppet/type/file_line.rb
parent70d071ba6fa3cf611e5dbdc1cba1343255edf978 (diff)
(#FM-6068) allow file encoding to be specified (#726)
* (#FM-6068) allow file encoding to be specified Add a new parameter `encoding` to allow non UTF-8 files to specify a file encoding. This prevents receiving the error message "invalid byte sequence in UTF-8" when special characters that are not UTF-8 encoded appear in the input stream, such as the copyright symbol. * (#FM-6068) allow file encoding to be specified Added docs and tests as requested
Diffstat (limited to 'lib/puppet/type/file_line.rb')
-rw-r--r--lib/puppet/type/file_line.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 7b7d44e..e82b246 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -48,6 +48,22 @@ Puppet::Type.newtype(:file_line) do
followed by HTTP_PROXY and delete it. If multiple lines match, an
error will be raised unless the `multiple => true` parameter is set.
+ Encoding example:
+
+ file_line { "XScreenSaver":
+ ensure => present,
+ path => '/root/XScreenSaver'
+ line => "*lock: 10:00:00",
+ match => '^*lock:',
+ encoding => "iso-8859-1",
+ }
+
+ Files with special characters that are not valid UTF-8 will give the
+ error message "invalid byte sequence in UTF-8". In this case, determine
+ the correct file encoding and specify the correct encoding using the
+ encoding attribute, the value of which needs to be a valid Ruby character
+ encoding.
+
**Autorequires:** If Puppet is managing the file that will contain the line
being managed, the file_line resource will autorequire that file.
EOT
@@ -107,6 +123,11 @@ Puppet::Type.newtype(:file_line) do
defaultto true
end
+ newparam(:encoding) do
+ desc 'For files that are not UTF-8 encoded, specify encoding such as iso-8859-1'
+ defaultto 'UTF-8'
+ end
+
# Autorequire the file resource if it's being managed
autorequire(:file) do
self[:path]