]> git.proxmox.com Git - pmg-api.git/commitdiff
quarantine: self service: early return for limit check, consistent code
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 18 Nov 2020 16:25:44 +0000 (17:25 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 18 Nov 2020 16:34:38 +0000 (17:34 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/API2/Quarantine.pm

index e7e8a5afe4b42c9e3383bfd740c9fc17bd995fff..f0d9003c0e61c15b174a09d41fa580411c172e9f 100644 (file)
@@ -1324,17 +1324,16 @@ __PACKAGE__->register_method ({
        }
 
        PVE::Tools::lock_file_full("${link_map_fn}.lck", 10, 1, sub {
-           if (-f $link_map_fn) {
-               # check if user is allowed to request mail
-               my $lines = [split("\n", PVE::Tools::file_get_contents($link_map_fn))];
-               for my $line (@$lines) {
-                   next if $line !~ m/^\Q$receiver\E (\d+)$/;
-                   if (($1 + $per_user_limit) > $starttime) {
-                       die "Too many requests for '$receiver', only one request per hour is permitted. ".
-                       "Please try again later\n";
-                   } else {
-                       last;
-                   }
+           return if !-f $link_map_fn;
+           # check if user is allowed to request mail
+           my $data = PVE::Tools::file_get_contents($link_map_fn);
+           for my $line (split("\n", $data)) {
+               next if $line !~ m/^\Q$receiver\E (\d+)$/;
+               if (($1 + $per_user_limit) > $starttime) {
+                   die "Too many requests for '$receiver', only one request per"
+                       ."hour is permitted. Please try again later\n";
+               } else {
+                   last;
                }
            }
        });