Rationale: This is used from cfs_write_file, which is now also used to write utf8-encoded strings that come from Rust. If no encoding is specified while writing the file, we run into problems with certain special characters (e.g. 'ΓΌ')
Signed-off-by: Lukas Wagner <l.wag...@proxmox.com> --- src/PVE/Tools.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 50240c8..f7224f8 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -237,7 +237,7 @@ sub lock_file { } sub file_set_contents { - my ($filename, $data, $perm) = @_; + my ($filename, $data, $perm, $encoding) = @_; $perm = 0644 if !defined($perm); @@ -247,6 +247,11 @@ sub file_set_contents { my ($fh, $tries) = (undef, 0); while (!$fh && $tries++ < 3) { $fh = IO::File->new($tmpname, O_WRONLY|O_CREAT|O_EXCL, $perm); + + if (defined($encoding)) { + binmode($fh, ":encoding($encoding)"); + } + if (!$fh && $! == EEXIST) { unlink($tmpname) or die "unable to delete old temp file: $!\n"; } -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel