storage plugins: en/decode volume notes as UTF-8
When writing into the file, explicitly utf8 encode it, and then try to utf8 decode it on read. If the notes are not valid utf8, we assume they were iso-8859 encoded and return as is. Technically this is a breaking change, since there are iso-8859 comments that would successfully decode as utf8, for example: the byte sequence "C2 A9" would be "£" in iso, but would decode to "£". From what i can tell though, this is rather unlikely to happen for "real world" notes, because the first byte would be in the range of C0-F7 (which are mostly language dependent characters like "Â") and the following bytes would have to be in the range of 80-BF, which are only special characters like "£" (or undefined) Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
7a8751a2cd
commit
43f8112f0b
@ -3,6 +3,7 @@ package PVE::Storage::Plugin;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Encode qw(decode);
|
||||
use Fcntl ':mode';
|
||||
use File::chdir;
|
||||
use File::Path;
|
||||
@ -1197,7 +1198,7 @@ my $get_subdir_files = sub {
|
||||
my $notes_fn = $original.NOTES_EXT;
|
||||
if (-f $notes_fn) {
|
||||
my $notes = PVE::Tools::file_read_firstline($notes_fn);
|
||||
$info->{notes} = $notes if defined($notes);
|
||||
$info->{notes} = eval { decode('UTF-8', $notes, 1) } // $notes if defined($notes);
|
||||
}
|
||||
|
||||
$info->{protected} = 1 if -e PVE::Storage::protection_file_path($original);
|
||||
|
||||
Reference in New Issue
Block a user