]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/DirPlugin.pm
pbs: detect mismatch of encryption settings and key
[pve-storage.git] / PVE / Storage / DirPlugin.pm
index c60818b7504737ae10628127201b1f5861faabf3..8715a9d3d8b4ef24548128646e4e030bb439c731 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 
 use Cwd;
+use Encode qw(decode encode);
 use File::Path;
 use IO::File;
 use POSIX;
@@ -58,6 +59,7 @@ sub options {
        disable => { optional => 1 },
        maxfiles => { optional => 1 },
        'prune-backups' => { optional => 1 },
+       'max-protected-backups' => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        mkdir => { optional => 1 },
@@ -92,9 +94,8 @@ sub parse_is_mountpoint {
     return $is_mp; # contains a path
 }
 
-# FIXME remove on the next APIAGE reset.
-# Deprecated, use get_volume_attribute instead.
-sub get_volume_notes {
+# FIXME move into 'get_volume_attribute' when removing 'get_volume_notes'
+my $get_volume_notes_impl = sub {
     my ($class, $scfg, $storeid, $volname, $timeout) = @_;
 
     my ($vtype) = $class->parse_volname($volname);
@@ -103,14 +104,23 @@ sub get_volume_notes {
     my $path = $class->filesystem_path($scfg, $volname);
     $path .= $class->SUPER::NOTES_EXT;
 
-    return PVE::Tools::file_get_contents($path) if -f $path;
+    if (-f $path) {
+       my $data = PVE::Tools::file_get_contents($path);
+       return eval { decode('UTF-8', $data, 1) } // $data;
+    }
 
     return '';
-}
+};
 
 # FIXME remove on the next APIAGE reset.
-# Deprecated, use update_volume_attribute instead.
-sub update_volume_notes {
+# Deprecated, use get_volume_attribute instead.
+sub get_volume_notes {
+    my ($class, $scfg, $storeid, $volname, $timeout) = @_;
+    return $get_volume_notes_impl->($class, $scfg, $storeid, $volname, $timeout);
+}
+
+# FIXME move into 'update_volume_attribute' when removing 'update_volume_notes'
+my $update_volume_notes_impl = sub {
     my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
 
     my ($vtype) = $class->parse_volname($volname);
@@ -120,18 +130,26 @@ sub update_volume_notes {
     $path .= $class->SUPER::NOTES_EXT;
 
     if (defined($notes) && $notes ne '') {
-       PVE::Tools::file_set_contents($path, $notes);
+       my $encoded = encode('UTF-8', $notes);
+       PVE::Tools::file_set_contents($path, $encoded);
     } else {
        unlink $path or $! == ENOENT or die "could not delete notes - $!\n";
     }
     return;
+};
+
+# FIXME remove on the next APIAGE reset.
+# Deprecated, use update_volume_attribute instead.
+sub update_volume_notes {
+    my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
+    return $update_volume_notes_impl->($class, $scfg, $storeid, $volname, $notes, $timeout);
 }
 
 sub get_volume_attribute {
     my ($class, $scfg, $storeid, $volname, $attribute) = @_;
 
     if ($attribute eq 'notes') {
-       return $class->get_volume_notes($scfg, $storeid, $volname);
+       return $get_volume_notes_impl->($class, $scfg, $storeid, $volname);
     }
 
     my ($vtype) = $class->parse_volname($volname);
@@ -149,7 +167,7 @@ sub update_volume_attribute {
     my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
 
     if ($attribute eq 'notes') {
-       return $class->update_volume_notes($scfg, $storeid, $volname, $value);
+       return $update_volume_notes_impl->($class, $scfg, $storeid, $volname, $value);
     }
 
     my ($vtype) = $class->parse_volname($volname);