make md5sums read-only
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 29 Jan 2011 14:54:49 +0000 (15:54 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 29 Jan 2011 14:54:49 +0000 (15:54 +0100)
bin/BackupPC_ASA_PostArchive_Update

index 475a477..93478c9 100755 (executable)
@@ -120,6 +120,13 @@ my $sth_inc_size = $dbh->prepare(qq{
        where id = ?
 });
 
+sub read_only {
+       my $full = shift;
+       my $perm = (stat $full)[2] & 0444;
+       warn sprintf("chmod %03o %s\n",$perm,$full);
+       chmod $perm, $full || die $!;
+}
+
 sub check_archive {
        my ($host,$num) = @_;
        warn "# check_archive $host $num";
@@ -144,6 +151,7 @@ sub check_archive {
 
        if ( ! -e $md5_path ) {
                system_ok "cd $Conf{ArchiveDest} && /usr/bin/md5sum $host.$num.* > $md5_path";
+               read_only $md5_path;
                $read_protect = 1;
        } else {
                system_ok "cd $Conf{ArchiveDest} && /usr/bin/md5sum -c $md5_path" if $opt->check;
@@ -153,12 +161,7 @@ sub check_archive {
        foreach ( split(/\n/, read_file "$Conf{ArchiveDest}/$host.$num.md5" ) ) {
                my ( $md5, $path ) = split(/\s+/,$_);
                $md5sum->{$path} = $md5;
-               if ( $read_protect ) {
-                       my $full = "$Conf{ArchiveDest}/$path";
-                       my $perm = (stat $full)[2] & 0444;
-                       warn sprintf("chmod %03o %s\n",$perm,$full);
-                       chmod $perm, $full;
-               }
+               read_only "$Conf{ArchiveDest}/$path" if $read_protect;
        }
 
        # depending on expected returned value this is used like: