added only_increment param to all action=browse links
[BackupPC.git] / lib / BackupPC / View.pm
index 7e4ae99..b47080d 100644 (file)
@@ -13,7 +13,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2002-2007  Craig Barratt
+#   Copyright (C) 2002-2009  Craig Barratt
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@
 #
 #========================================================================
 #
-# Version 3.1.0, released 25 Nov 2007.
+# Version 3.2.0, released 31 Jul 2010.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -48,6 +48,8 @@ use BackupPC::FileZIO;
 use Data::Dumper;
 use Encode qw/from_to/;
 
+use Data::Dump qw(dump);
+
 sub new
 {
     my($class, $bpc, $host, $backups, $options) = @_;
@@ -93,17 +95,34 @@ sub dirCache
     $m->{share} = $share;
     $m->{dir} = $dir;
 
+    my $previous_increment_entry;
+    my $increment_backupNum = $backupNum; # used in loop
+    my @visit_backup_ids;
+    my $i;
+    for ( $i = $m->{idx} ; $i >= 0 ; $i-- ) {
+
+       # we need two incremental backups to detect changes
+       next if $m->{backups}[$i]{level} >= $level && $#visit_backup_ids > 0;
+
+       push @visit_backup_ids, $i;
+
+       # for first full backup we need another full to detect changes
+       last if $m->{backups}[$i]{level} == 0 && $#visit_backup_ids > 0;
+    }
+    #warn "# visit_backup_ids = ",dump @visit_backup_ids;
+
     #
     # merge backups, starting at the requested one, and working
     # backwards until we get to level 0.
     #
     $m->{mergeNums} = [];
-    for ( $i = $m->{idx} ; $level > 0 && $i >= 0 ; $i-- ) {
+#    for ( $i = $m->{idx} ; $level > 0 && $i >= 0 ; $i-- ) {
+    for my $i ( @visit_backup_ids ) {
        #print(STDERR "Do $i ($m->{backups}[$i]{noFill},$m->{backups}[$i]{level})\n");
        #
        # skip backups with the same or higher level
        #
-       next if ( $m->{backups}[$i]{level} >= $level );
+       #next if ( $m->{backups}[$i]{level} >= $level ); # ASA - visit_backup_ids
 
        $level = $m->{backups}[$i]{level};
        $backupNum = $m->{backups}[$i]{num};
@@ -123,6 +142,8 @@ sub dirCache
         #print(STDERR "Opening $path (share=$share, mangle=$mangle)\n");
 
         my $dirOpts    = { %{$m->{dirOpts} || {} } };
+        $dirOpts->{inode} = 1 if $m->{dirOpts}->{only_increment}; # ASA - detect unchanged
+#warn "# dirOpts = ",dump $dirOpts;
         my $attribOpts = { compress => $compress };
         if ( $legacyCharset ) {
             $dirOpts->{charsetLegacy}
@@ -157,14 +178,34 @@ sub dirCache
            #
            # skip special files
            #
-            next if ( defined($m->{files}{$fileUM})
+            next if ( 0 # defined($m->{files}{$fileUM}) # ASA - need fallthrough
                    || $file eq ".."
                    || $file eq "."
                    || $file eq "backupInfo"
                    || $mangle && $file eq "attrib" );
 
+
+               # ASA - we only skip files when invoked with share name
+               if ( $m->{dirOpts}->{only_increment} && $share ) {
+                       if ( defined $previous_increment_entry->{$fileUM}
+                       && $previous_increment_entry->{$fileUM}->{inode} == $entry->{inode} ) {
+                               #warn "# -- $backupNum $fileUM\n";
+                               $previous_increment_entry->{$fileUM}->{_hide}++;
+                               next;
+                       } elsif ( $backupNum < $increment_backupNum ) {
+                               #warn "# << $backupNum $fileUM\n";
+                               next;
+                       } else {
+                               #warn "# ++ $backupNum $fileUM ",dump $entry;
+                               $previous_increment_entry->{$fileUM} = $entry;
+                       }
+               } else {
+                       next if defined($m->{files}{$fileUM});
+               }
+
             if ( defined($attr) && defined(my $a = $attr->get($fileUM)) ) {
                 $m->{files}{$fileUM} = $a;
+               $previous_increment_entry->{$fileUM}->{_dir}++ if $a->{type} == BPC_FTYPE_DIR; # ASA
                 #
                 # skip directories in earlier backups (each backup always
                 # has the complete directory tree).
@@ -223,6 +264,7 @@ sub dirCache
            $m->{files}{$fileUM}{inode}       = $entry->{inode}
                                                     if ( $m->{dirOpts}{inode} );
         }
+
        #
        # Also include deleted files
        #
@@ -245,6 +287,16 @@ sub dirCache
            }
        }
     }
+
+       # ASA create increment
+       if ( $m->{dirOpts}->{only_increment} ) {
+               warn "# previous_increment_entry = ",dump $previous_increment_entry;
+               foreach my $file ( grep { exists $previous_increment_entry->{$_}->{_hide} && ! exists $previous_increment_entry->{$_}->{_dir} } keys %$previous_increment_entry ) {
+                       delete $m->{files}{$file};
+                       #warn "OLD $file\n";
+               }
+       }
+
     #
     # Prune deleted files
     #