[pve-devel] [PATCH common v3 1/3] de- and encode comments in /etc/network/interfaces as utf8
Dominik Csapak
d.csapak at proxmox.com
Wed Sep 12 10:24:09 CEST 2018
decode comments as utf8 during reading
and encode it during writing
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v2:
* also encode when writing
src/PVE/INotify.pm | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index fc9471d..dee9a3e 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -873,10 +873,9 @@ sub __read_etc_network_interfaces {
while (defined ($line = <$fh>)) {
chomp $line;
if ($line =~ m/^\s*#(.*?)\s*$/) {
- # NOTE: we use 'comments' instead of 'comment' to
- # avoid automatic utf8 conversion
$f->{comments} = '' if !$f->{comments};
- $f->{comments} .= "$1\n";
+ my $comment = decode('UTF-8', $1);
+ $f->{comments} .= "$comment\n";
} elsif ($line =~ m/^\s*(?:iface\s
|mapping\s
|auto\s
@@ -1252,7 +1251,7 @@ sub write_etc_network_interfaces {
my ($filename, $fh, $config) = @_;
my $ifupdown2 = -e '/usr/share/ifupdown2';
my $raw = __write_etc_network_interfaces($config, $ifupdown2);
- PVE::Tools::safe_print($filename, $fh, $raw);
+ PVE::Tools::safe_print($filename, $fh, encode('UTF-8', $raw));
}
sub __write_etc_network_interfaces {
my ($config, $ifupdown2) = @_;
--
2.11.0
More information about the pve-devel
mailing list