[PATCH pve-storage v1 32/54] api: status: simplify recently added parsing helper for file transfers

Max R. Carrara
2026-04-22T11:19:02Z

Since we already assert whether we can transfer files for a given
volume type using the `assert_can_transfer_files()` helper, and also
raise an exception if parsing fails, handling the parsing of each
volume type individually is not necessary anymore.

Therefore, pull out the common parts of the branches for individual
volume types.

Retain only the special case for the `import` type where we do not
accept `.ovf` files.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
src/PVE/API2/Storage/Status.pm | 40 ++++++----------------------------
1 file changed, 7 insertions(+), 33 deletions(-)

diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm
index b578a1ed..bff59b66 100644
--- a/src/PVE/API2/Storage/Status.pm
+++ b/src/PVE/API2/Storage/Status.pm
@@ -73,45 +73,19 @@ my sub assert_can_transfer_files : prototype($$$) {
my sub parse_transferred_file_path_extension : prototype($$) {
my ($path, $vtype) = @_;

- if ($vtype eq 'iso') {
- my $parts = parse_path_as_volname_parts($path, $vtype);
+ my $parts = parse_path_as_volname_parts($path, $vtype);

- if (!defined($parts)) {
- raise_param_exc({ filename => "wrong file extension" });
- }
-
- my $ext = $parts->{ext};
- return $ext;
+ if (!defined($parts)) {
+ raise_param_exc({ filename => "invalid filename or wrong file extension" });
}

- if ($vtype eq 'vztmpl') {
- my $parts = parse_path_as_volname_parts($path, $vtype);
+ my $ext = $parts->{ext};

- if (!defined($parts)) {
- raise_param_exc({ filename => "wrong file extension" });
- }
-
- my $ext = $parts->{ext};
- return $ext;
+ if ($vtype eq 'import' && $ext eq 'ovf') {
+ raise_param_exc({ filename => "wrong file extension" });
}

- if ($vtype eq 'import') {
- my $parts = parse_path_as_volname_parts($path, $vtype);
-
- if (!defined($parts)) {
- raise_param_exc({ filename => "invalid filename or wrong extension" });
- }
-
- my $ext = $parts->{ext};
-
- if ($ext eq 'ovf') {
- raise_param_exc({ filename => "wrong file extension" });
- }
-
- return $ext;
- }
-
- die "upload / download: failed to parse '$path' - unhandled content type '$vtype'\n";
+ return $ext;
}

my sub assert_file_transfer_contents_valid : prototype($$$) {
--
2.47.3