[pve-devel] [PATCH v2 storage] config: use relative paths for content overrides

Leo Nunner l.nunner at proxmox.com
Tue Mar 14 14:14:54 CET 2023


Remove the requirement for paths to start with a /, as it might be
confusing to users.

Signed-off-by: Leo Nunner <l.nunner at proxmox.com>
---
RFC: I'm not really sure how much input validation we want to do here.
e.g., should we keep the user from appending or prepending slashes (e.g.
setting the override as /dir/)? Or should we just accept everything?

 PVE/Storage/Plugin.pm   | 6 +++---
 test/get_subdir_test.pm | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index ca7a0d4..6295aa2 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -355,7 +355,7 @@ PVE::JSONSchema::register_format('pve-dir-override', \&verify_dir_override);
 sub verify_dir_override {
     my ($value, $noerr) = @_;
 
-    if($value =~ m/^([a-z]+)=\/.+$/ &&
+    if($value =~ m/^([a-z]+)=[^.]+$/ &&
 	verify_content($1, $noerr)) {
 	return $value;
     }
@@ -659,9 +659,9 @@ sub get_subdir {
     die "storage definition has no path\n" if !$path;
     die "unknown vtype '$vtype'\n" if !exists($vtype_subdirs->{$vtype});
 
-    my $subdir = $scfg->{"content-dirs"}->{$vtype} // "/".$vtype_subdirs->{$vtype};
+    my $subdir = $scfg->{"content-dirs"}->{$vtype} // $vtype_subdirs->{$vtype};
 
-    return $path.$subdir;
+    return "$path/$subdir";
 }
 
 sub filesystem_path {
diff --git a/test/get_subdir_test.pm b/test/get_subdir_test.pm
index ff42985..b9d61d5 100644
--- a/test/get_subdir_test.pm
+++ b/test/get_subdir_test.pm
@@ -29,9 +29,9 @@ foreach my $type (keys %$vtype_subdirs) {
 
 # creates additional tests for overrides
 foreach my $type (keys %$vtype_subdirs) {
-    my $override = "/${type}_override";
+    my $override = "${type}_override";
     my $scfg_with_override = { path => '/some/path', 'content-dirs' => { $type => $override } };
-    push @$tests, [ $scfg_with_override, $type, "$scfg_with_override->{path}$scfg_with_override->{'content-dirs'}->{$type}" ];
+    push @$tests, [ $scfg_with_override, $type, "$scfg_with_override->{path}/$scfg_with_override->{'content-dirs'}->{$type}" ];
 }
 
 plan tests => scalar @$tests;
-- 
2.30.2






More information about the pve-devel mailing list