- fixed bug that occured while calculating total dvd size
[BackupPC.git] / lib / BackupPC / CGI / BurnMedia.pm
index e6beac2..8f29a07 100644 (file)
@@ -42,21 +42,29 @@ EOF
 
                my $parts = 1;
                foreach my $key(keys(%In)) {
-                       print LOG "doing $key...";
                        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;
-                               my $currSize = BackupPC::SearchLib::getGzipSize($host_id, $backup_num);
-                               if ($currSize > 0) {
-                                       $total_size += currSize;
+                               my $currSize = BackupPC::SearchLib::getGzipSizeFromBackupID($backup_id);
+                               my $sth_size = $dbh->prepare(q{select inc_size from backups where id = ?});
+                               $sth_size -> execute( $backup_id );
+                               my $db_size = $sth_size->fetchrow_hashref()->{inc_size};
+
+                               if ($db_size != $currSize) {
+                                       $cont .= "NOT EQUAL!: [fs_size:$currSize, db_size:$db_size, backup_id:$backup_id] <br />";
                                }
+                               
+                               if ($currSize > 0) {
+                                       $total_size += $currSize;
+                               } 
                                $selected++;
 
                                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)}});
@@ -112,11 +120,18 @@ EOF
 
                        $dbh->commit();
 
+                       my $db_size = 0;
+                       $sth = $dbh->prepare('SELECT SUM(gzip_size) AS suma FROM backups_on_dvds WHERE dvd_nr=?');
+                       $sth->execute($dvd_nr);
+                       $db_size = $sth->fetchrow_hashref()->{suma};
+                       $sth->finish();
+                       
                        $cont .= q{
                                Archived following backups:
                        } . join(", ", @selected_backup_ids) . q{
                                <br/>with total size of
-                       <b>} . sprintf("%1.2f Mb", $total_size / 1024 / 1024) . q{</b>
+                       <b>} . sprintf("%1.2f Mb", $total_size / 1024 / 1024) 
+                       . q{</b>
                                to media <b>} . $dvd_nr . q{</b>
                                with following message:
                                <div style="background-color: #e0e0e0; display: inline; padding: 2px;">