[pmg-devel] [PATCH pmg-api] api: apt: repos: avoid creating implicit default for enabled

Fabian Ebner f.ebner at proxmox.com
Fri Jul 16 15:42:36 CEST 2021


The parameter is optional, so a check for definedness is needed before
converting to int.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PMG/API2/APT.pm | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/PMG/API2/APT.pm b/src/PMG/API2/APT.pm
index 6d0f651..5e132c4 100644
--- a/src/PMG/API2/APT.pm
+++ b/src/PMG/API2/APT.pm
@@ -749,9 +749,10 @@ __PACKAGE__->register_method({
     code => sub {
 	my ($param) = @_;
 
-	my $options = {
-	    enabled => int($param->{enabled}),
-	};
+	my $options = {};
+
+	my $enabled = $param->{enabled};
+	$options->{enabled} = int($enabled) if defined($enabled);
 
 	PMG::RS::APT::Repositories::change_repository(
 	    $param->{path},
-- 
2.30.2





More information about the pmg-devel mailing list