Release for 3.2.0. Changes since 3.2.0beta1:
[BackupPC.git] / lib / BackupPC / Storage / Text.pm
index b99648d..b3318db 100644 (file)
@@ -12,7 +12,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2004  Craig Barratt
+#   Copyright (C) 2004-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
@@ -30,7 +30,7 @@
 #
 #========================================================================
 #
-# Version 3.0.0, released 28 Jan 2007.
+# Version 3.2.0, released 31 Jul 2010.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -85,16 +85,15 @@ sub BackupInfoRead
     }
     close(LOCK);
     #
-    # Default the level and version fields if not present
+    # Default the version field.  Prior to 3.0.0 the xferMethod
+    # field is empty, so we use that to figure out the version.
     #
     for ( my $i = 0 ; $i < @Backups ; $i++ ) {
-        if ( defined($Backups[$i]{level}) ) {
-            if ( !defined($Backups[$i]{version}) ) {
-                $Backups[$i]{version} = "3.0.0";
-            }
-        } else {
-            $Backups[$i]{level} = $Backups[$i]{type} eq "incr" ? 1 : 0;
+        next if ( $Backups[$i]{version} ne "" );
+        if ( $Backups[$i]{xferMethod} eq "" ) {
             $Backups[$i]{version} = "2.1.2";
+        } else {
+            $Backups[$i]{version} = "3.0.0";
         }
     }
     return @Backups;
@@ -215,7 +214,10 @@ sub TextFileWrite
 
     (my $dir = $file) =~ s{(.+)/(.+)}{$1};
 
-    mkpath($dir, 0, 0775) if ( !-d $dir );
+    if ( !-d $dir ) {
+        eval { mkpath($dir, 0, 0775) };
+        return "TextFileWrite: can't create directory $dir" if ( $@ );
+    }
     if ( open(FD, ">", "$file.new") ) {
        binmode(FD);
         print FD $contents;
@@ -272,25 +274,25 @@ sub ConfigPath
 
 sub ConfigDataRead
 {
-    my($s, $host) = @_;
+    my($s, $host, $prevConfig) = @_;
     my($ret, $mesg, $config, @configs);
 
     #
     # TODO: add lock
     #
-    my $conf = {};
+    my $conf = $prevConfig || {};
     my $configPath = $s->ConfigPath($host);
 
     push(@configs, $configPath) if ( -f $configPath );
     foreach $config ( @configs ) {
-        %Conf = ();
+        %Conf = %$conf;
         if ( !defined($ret = do $config) && ($! || $@) ) {
             $mesg = "Couldn't open $config: $!" if ( $! );
             $mesg = "Couldn't execute $config: $@" if ( $@ );
             $mesg =~ s/[\n\r]+//;
             return ($mesg, $conf);
         }
-        %$conf = ( %$conf, %Conf );
+        %$conf = %Conf;
     }
 
     #
@@ -320,11 +322,6 @@ sub ConfigDataRead
         delete($conf->{BlackoutWeekDays});
     }
 
-    #
-    # Make sure IncrLevels is defined
-    #
-    $conf->{IncrLevels} = [1] if ( !defined($conf->{IncrLevels}) );
-
     return (undef, $conf);
 }