r11656@llin: dpavlin | 2005-12-13 00:31:55 +0100
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Tue, 13 Dec 2005 00:10:45 +0000 (00:10 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Tue, 13 Dec 2005 00:10:45 +0000 (00:10 +0000)
 fix backup size calculation

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@263 8392b6e1-25fa-0310-8288-cc32f8e212ea

lib/BackupPC/CGI/BurnMedia.pm

index 59df5aa..0bd4bff 100644 (file)
@@ -40,24 +40,24 @@ EOF
                my $total_size = 0;
                my $selected = 0;
 
+               my $parts = 1;
+
                foreach my $key(keys(%In)) {
                        if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
                                my ($host_id, $backup_num, $backup_id) = ($1,$2,$3);
                                push @selected_backup_ids, $backup_id;
                                $total_size += BackupPC::SearchLib::getGzipSize($host_id, $backup_num);
                                $selected++;
-                       }
-               }
 
-               # and now a little magic to check multi-volume increments
-               my $parts = 1;
-               if ($#selected_backup_ids == 0) {
-                       ($parts) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $selected_backup_ids[0]);
+                               my ($this_part) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $backup_id);
+                               $this_part--;
+                               $parts += $this_part;
+                       }
                }
 
                if ($total_size > ($Conf{MaxArchiveSize} * $parts)) {
                        $cont .= eval( q{ ${h2(Error)}});
-                       $cont .= "Selected backups size $total_size Kb exceed max archive size $Conf{MaxArchiveSize} Kb.";
+                       $cont .= "Selected backups size " . sprintf("%1.2f", $total_size / 1024) ." Kb exceed max archive size " . sprintf("%1.2f", $Conf{MaxArchiveSize} / 1024) ." Kb.";
                } elsif ($total_size == 0) {
                        $cont .= eval( q{ ${h2(Error)}});
                        $cont .= "No backups selected.";
@@ -65,22 +65,22 @@ EOF
 
                        # create new archive
                        my $sth = $dbh->prepare(q{
-                                                       INSERT INTO archive (
-                                                               id,
-                                                               dvd_nr,
-                                                               note,
-                                                               username,
-                                                               date,
-                                                               total_size
-                                                       ) VALUES (
-                                                               nextVal('archive_id_seq'),
-                                                               nextVal('dvd_nr'),
-                                                               ?,
-                                                               ?,
-                                                               NOW(),
-                                                               ?
-                                                       )
-                                               });
+                               INSERT INTO archive (
+                                       id,
+                                       dvd_nr,
+                                       note,
+                                       username,
+                                       date,
+                                       total_size
+                               ) VALUES (
+                                       nextVal('archive_id_seq'),
+                                       nextVal('dvd_nr'),
+                                       ?,
+                                       ?,
+                                       NOW(),
+                                       ?
+                               )
+                       });
 
                        $sth->execute($In{'note'}, $User, $total_size);