public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-common 1/3] tools: allow to specify file encoding for file_set_contents
Date: Wed, 30 Aug 2023 14:37:52 +0200	[thread overview]
Message-ID: <20230830123754.606260-2-l.wagner@proxmox.com> (raw)
In-Reply-To: <20230830123754.606260-1-l.wagner@proxmox.com>

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.wagner@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





  reply	other threads:[~2023-08-30 12:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 12:37 [pve-devel] [PATCH common/cluster 0/3] fix #4937: fix utf8 encoding issues while saving notification config Lukas Wagner
2023-08-30 12:37 ` Lukas Wagner [this message]
2023-08-30 12:37 ` [pve-devel] [PATCH pve-cluster 2/3] cluster fs: allow to specify file encoding for cfs_write_file Lukas Wagner
2023-08-30 12:37 ` [pve-devel] [PATCH pve-cluster 3/3] fix #4937: notify: write configuration files in utf8 encoding Lukas Wagner
2023-09-01  7:40 ` [pve-devel] [PATCH common/cluster 0/3] fix #4937: fix utf8 encoding issues while saving notification config Lukas Wagner
2023-09-11 12:50 ` [pve-devel] applied-series: " Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230830123754.606260-2-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal