Updates in preparation for 3.0.0beta2:
[BackupPC.git] / lib / BackupPC / View.pm
index 66de030..b71eecb 100644 (file)
@@ -31,7 +31,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0, released 20 Jun 2004.
+# Version 3.0.0beta2, released 11 Nov 2006.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -140,7 +140,7 @@ sub dirCache
            }
        }
         foreach my $file ( @dir ) {
-            $file = $1 if ( $file =~ /(.*)/ );
+            $file = $1 if ( $file =~ /(.*)/s );
             my $fileUM = $file;
             $fileUM = $m->{bpc}->fileNameUnmangle($fileUM) if ( $mangle );
             #print(STDERR "Doing $fileUM\n");
@@ -150,6 +150,7 @@ sub dirCache
             next if ( defined($m->{files}{$fileUM})
                    || $file eq ".."
                    || $file eq "."
+                   || $file eq "backupInfo"
                    || $mangle && $file eq "attrib" );
            #
            # skip directories in earlier backups (each backup always
@@ -192,13 +193,14 @@ sub dirCache
                     }
                 }
             }
-            $m->{files}{$fileUM}{relPath}    = "$dir/$fileUM";
-            $m->{files}{$fileUM}{sharePathM} = "$sharePathM/$file";
-            $m->{files}{$fileUM}{fullPath}   = "$path/$file";
-            $m->{files}{$fileUM}{backupNum}  = $backupNum;
-            $m->{files}{$fileUM}{compress}   = $compress;
-           $m->{files}{$fileUM}{nlink}      = $s[3];
-           $m->{files}{$fileUM}{inode}      = $s[1];
+            ($m->{files}{$fileUM}{relPath}    = "$dir/$fileUM") =~ s{//+}{/}g;
+            ($m->{files}{$fileUM}{sharePathM} = "$sharePathM/$file")
+                                                               =~ s{//+}{/}g;
+            ($m->{files}{$fileUM}{fullPath}   = "$path/$file") =~ s{//+}{/}g;
+            $m->{files}{$fileUM}{backupNum}   = $backupNum;
+            $m->{files}{$fileUM}{compress}    = $compress;
+           $m->{files}{$fileUM}{nlink}       = $s[3];
+           $m->{files}{$fileUM}{inode}       = $s[1];
         }
        #
        # Also include deleted files
@@ -247,10 +249,12 @@ sub shareList
     my @dir = readdir(DIR);
     closedir(DIR);
     foreach my $file ( @dir ) {
-        $file = $1 if ( $file =~ /(.*)/ );
+        $file = $1 if ( $file =~ /(.*)/s );
         next if ( $file eq "attrib" && $mangle
                || $file eq "."
-               || $file eq ".." );
+               || $file eq ".."
+               || $file eq "backupInfo"
+            );
         my $fileUM = $file;
         $fileUM = $m->{bpc}->fileNameUnmangle($fileUM) if ( $mangle );
         push(@shareList, $fileUM);
@@ -285,7 +289,7 @@ sub fileAttrib
     my($m, $backupNum, $share, $path) = @_;
 
     #print(STDERR "fileAttrib($backupNum, $share, $path)\n");
-    if ( $path =~ s{(.*)/+(.+)}{$1} ) {
+    if ( $path =~ s{(.*)/+(.+)}{$1}s ) {
         my $file = $2;
         $m->dirCache($backupNum, $share, $path);
         return $m->{files}{$file};
@@ -397,7 +401,7 @@ sub dirHistory
            }
        }
         foreach my $file ( @dir ) {
-            $file = $1 if ( $file =~ /(.*)/ );
+            $file = $1 if ( $file =~ /(.*)/s );
             my $fileUM = $file;
             $fileUM = $m->{bpc}->fileNameUnmangle($fileUM) if ( $mangle );
             #print(STDERR "Doing $fileUM\n");
@@ -444,15 +448,27 @@ sub dirHistory
                     }
                 }
             }
-            $files->{$fileUM}[$i]{relPath}    = "$dir/$fileUM";
-            $files->{$fileUM}[$i]{sharePathM} = "$sharePathM/$file";
-            $files->{$fileUM}[$i]{fullPath}   = "$path/$file";
-            $files->{$fileUM}[$i]{backupNum}  = $backupNum;
-            $files->{$fileUM}[$i]{compress}   = $compress;
-           $files->{$fileUM}[$i]{nlink}      = $s[3];
-           $files->{$fileUM}[$i]{inode}      = $s[1];
+            ($files->{$fileUM}[$i]{relPath}    = "$dir/$fileUM") =~ s{//+}{/}g;
+            ($files->{$fileUM}[$i]{sharePathM} = "$sharePathM/$file")
+                                                                =~ s{//+}{/}g;
+            ($files->{$fileUM}[$i]{fullPath}   = "$path/$file") =~ s{//+}{/}g;
+            $files->{$fileUM}[$i]{backupNum}   = $backupNum;
+            $files->{$fileUM}[$i]{compress}    = $compress;
+           $files->{$fileUM}[$i]{nlink}       = $s[3];
+           $files->{$fileUM}[$i]{inode}       = $s[1];
         }
 
+       #
+       # Flag deleted files
+       #
+       if ( defined($attr) ) {
+           my $a = $attr->get;
+           foreach my $fileUM ( keys(%$a) ) {
+               next if ( $a->{$fileUM}{type} != BPC_FTYPE_DELETED );
+               $files->{$fileUM}[$i]{type} = BPC_FTYPE_DELETED;
+           }
+       }
+
        #
        # Merge old backups.  Don't merge directories from old
        # backups because every backup has an accurate directory
@@ -468,18 +484,19 @@ sub dirHistory
                $files->{$fileUM}[$i] = $files->{$fileUM}[$k];
            }
        }
+    }
 
-       #
-       # Finally, remove deleted files
-       #
-       if ( defined($attr) ) {
-           my $a = $attr->get;
-           foreach my $fileUM ( keys(%$a) ) {
-               next if ( $a->{$fileUM}{type} != BPC_FTYPE_DELETED );
-               $files->{$fileUM}[$i] = undef if ( defined($files->{$fileUM}) );
-           }
-       }
+    #
+    # Remove deleted files
+    #
+    for ( $i = 0 ; $i < @{$m->{backups}} ; $i++ ) {
+        foreach my $fileUM ( keys(%$files) ) {
+            next if ( !defined($files->{$fileUM}[$i])
+                    || $files->{$fileUM}[$i]{type} != BPC_FTYPE_DELETED );
+            $files->{$fileUM}[$i] = undef;
+        }
     }
+
     #print STDERR "Returning:\n", Dumper($files);
     return $files;
 }