[PATCH pve-storage v1 14/54] storage: break up needless if-elsif chain in path_to_volume_id

Max R. Carrara
2026-04-22T11:15:25Z

src/PVE/Storage.pm | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index 70844602..e9b0cb7e 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -735,19 +735,31 @@ sub path_to_volume_id {
return ('images', $info->{volid});
}
}
- } elsif ($path =~ m!^\Q$isodir\E/([^/]+$ISO_EXT_RE_0)$!) {
+
+ return ('');
+ }
+
+ if ($path =~ m!^\Q$isodir\E/([^/]+$ISO_EXT_RE_0)$!) {
my $name = $1;
return ('iso', "$sid:iso/$name");
- } elsif ($path =~ m!^\Q$tmpldir\E/([^/]+$VZTMPL_EXT_RE_1)$!) {
+ }
+
+ if ($path =~ m!^\Q$tmpldir\E/([^/]+$VZTMPL_EXT_RE_1)$!) {
my $name = $1;
return ('vztmpl', "$sid:vztmpl/$name");
- } elsif ($path =~ m!^\Q$backupdir\E/([^/]+$BACKUP_EXT_RE_2)$!) {
+ }
+
+ if ($path =~ m!^\Q$backupdir\E/([^/]+$BACKUP_EXT_RE_2)$!) {
my $name = $1;
return ('backup', "$sid:backup/$name");
- } elsif ($path =~ m!^\Q$snippetsdir\E/([^/]+)$!) {
+ }
+
+ if ($path =~ m!^\Q$snippetsdir\E/([^/]+)$!) {
my $name = $1;
return ('snippets', "$sid:snippets/$name");
- } elsif ($path =~ m!^\Q$importdir\E/(${SAFE_CHAR_CLASS_RE}+${IMPORT_EXT_RE_1})$!) {
+ }
+
+ if ($path =~ m!^\Q$importdir\E/(${SAFE_CHAR_CLASS_RE}+${IMPORT_EXT_RE_1})$!) {
my $name = $1;
return ('import', "$sid:import/$name");
}
--
2.47.3