mhonarc-commits
[Top] [All Lists]

CVS: mhonarc/MHonArc/lib mhamain.pl,2.37,2.38

2002-05-13 18:55:45
Update of /cvsroot/mhonarc/mhonarc/MHonArc/lib
In directory subversions:/tmp/cvs-serv27892

Modified Files:
	mhamain.pl 
Log Message:
* Fixed Bug #396.
* MODTIME reset to 0 if platform does not support utime().
* Wrapped file_open() calls in eval when reading input so processing
  can continue even if some input cannot be accessed.  This was the
  intent all along, but file_open() will die on error.
* Catch file_open() error in output_mail() and delete message information
  inorder to recover in case a message page was removed outside of
  MHonArc.  This is not really enough since the index pages
  and index message listing arrays need to be adjusted.  However, it
  should make the archive still usable and corrected via a -editix
  pass.


Index: mhamain.pl
===================================================================
RCS file: /cvsroot/mhonarc/mhonarc/MHonArc/lib/mhamain.pl,v
retrieving revision 2.37
retrieving revision 2.38
diff -C2 -r2.37 -r2.38
*** mhamain.pl	9 May 2002 03:24:44 -0000	2.37
--- mhamain.pl	14 May 2002 01:13:30 -0000	2.38
***************
*** 296,300 ****
  	my($mbox, $mesgfile, @files);
  
! 	foreach $mbox (@ARGV) {
  
  	    ## MH mail folder (a directory)
--- 296,300 ----
  	my($mbox, $mesgfile, @files);
  
! 	MAILFOLDER: foreach $mbox (@ARGV) {
  
  	    ## MH mail folder (a directory)
***************
*** 309,317 ****
  						 readdir(MAILDIR));
  		closedir(MAILDIR);
! 		foreach (@files) {
  		    $mesgfile = "${mbox}${DIRSEP}${_}";
! 		    if (!($fh = file_open($mesgfile))) {
! 			warn "\nWarning: Unable to open message $mesgfile\n";
! 			next;
  		    }
  		    print STDOUT "."  unless $QUIET;
--- 309,323 ----
  						 readdir(MAILDIR));
  		closedir(MAILDIR);
! 
! 		local($_);
! 		MHFILE: foreach (@files) {
  		    $mesgfile = "${mbox}${DIRSEP}${_}";
! 		    eval {
! 			$fh = file_open($mesgfile);
! 		    };
! 		    if ($@) {
! 			warn $@,
! 			     qq/...Skipping "$mesgfile"\n/;
! 			next MHFILE;
  		    }
  		    print STDOUT "."  unless $QUIET;
***************
*** 330,334 ****
  			if ($SLOW && $DoArchive) {
  			    output_mail($index, 1, 1);
! 			    $Update{$IndexNum{$index}} = 1;
  			}
  			if ($SLOW || !$DoArchive) {
--- 336,342 ----
  			if ($SLOW && $DoArchive) {
  			    output_mail($index, 1, 1);
! 			    if (defined($IndexNum{$index})) {
! 				$Update{$IndexNum{$index}} = 1;
! 			    }
  			}
  			if ($SLOW || !$DoArchive) {
***************
*** 344,350 ****
  		if ($mbox eq "-") {
  		    $fh = $MhaStdin;
! 		} elsif (!($fh = &file_open($mbox))) {
! 		    warn "\nWarning: Unable to open $mbox\n";
! 		    next;
  		}
  
--- 352,364 ----
  		if ($mbox eq "-") {
  		    $fh = $MhaStdin;
! 		} else {
! 		    eval {
! 			$fh = file_open($mbox);
! 		    };
! 		    if ($@) {
! 			warn $@,
! 			     qq/...Skipping "$mbox"\n/;
! 			next MAILFOLDER;
! 		    }
  		}
  
***************
*** 366,370 ****
  			if ($SLOW && $DoArchive) {
  			    output_mail($index, 1, 1);
! 			    $Update{$IndexNum{$index}} = 1;
  			}
  			if ($SLOW || !$DoArchive) {
--- 380,386 ----
  			if ($SLOW && $DoArchive) {
  			    output_mail($index, 1, 1);
! 			    if (defined($IndexNum{$index})) {
! 				$Update{$IndexNum{$index}} = 1;
! 			    }
  			}
  			if ($SLOW || !$DoArchive) {
***************
*** 405,410 ****
  ##
  sub write_pages {
!     my($i, $key, $index, $tmp, $tmp2);
      my(@array2);
  
      ## Remove old message if hit maximum size or expiration
--- 421,427 ----
  ##
  sub write_pages {
!     my($i, $j, $key, $index, $tmp, $tmp2);
      my(@array2);
+     my($mloc, $tloc);
  
      ## Remove old message if hit maximum size or expiration
***************
*** 424,428 ****
  
  	## Expiration based upon time
- 	my($mloc, $tloc);
  	foreach $index (sort_messages(0,0,0,0)) {
  	    last  unless
--- 441,444 ----
***************
*** 534,537 ****
--- 550,563 ----
  		    $Update{$IndexNum{$TListOrder[$i+1]}} = 1
  			if $i < $#TListOrder;
+ 
+ 		    $tloc = $Index2TLoc{$index};
+ 		    for ($j=2; $j <= $TSliceNBefore; ++$j) {
+ 			$Update{$IndexNum{$TListOrder[$tloc-$j]}} = 1
+ 			    if $tloc-$j >= 0;
+ 		    }
+ 		    for ($j=2; $j <= $TSliceNAfter; ++$j) {
+ 			$Update{$IndexNum{$TListOrder[$tloc+$j]}} = 1
+ 			    if $tloc-$j >= $#TListOrder;
+ 		    }
  		}
  		$i++;
***************
*** 962,965 ****
--- 988,994 ----
  ##	    $nocustom	=> ignore sections with user customization
  ##
+ ##	This function returns ($msgnum, $filename) if everything went
+ ##	okay, but no calls to this routine check the return values.
+ ##
  sub output_mail {
      my($index, $force, $nocustom) = @_;
***************
*** 967,980 ****
      my($msghandle, $msginfh, $drvfh);
  
      my $adding	     = ($ADD && !$force && !$SINGLE);
!     my $i_p0 	     = fmt_msgnum($IndexNum{$index});
!     my $filename     = msgnum_filename($IndexNum{$index});
      my $filepathname = join($DIRSEP, $OUTDIR, $filename);
      my $tmppathname  = join($DIRSEP, $OUTDIR, "msgtmp.$$");
  
      if ($adding) {
! 	return ($i_p0, $filename)  unless $Update{$IndexNum{$index}};
  	#&file_rename($filepathname, $tmppathname);
! 	$msginfh = file_open($filepathname);
      }
      if ($SINGLE) {
--- 996,1029 ----
      my($msghandle, $msginfh, $drvfh);
  
+     my $msgnum	     = $IndexNum{$index};
+     if (!defined($msgnum)) {
+       # Something bad must have happened to message, so we just
+       # quietly return.
+       return;
+     }
+ 
      my $adding	     = ($ADD && !$force && !$SINGLE);
!     my $i_p0 	     = fmt_msgnum($msgnum);
!     my $filename     = msgnum_filename($msgnum);
      my $filepathname = join($DIRSEP, $OUTDIR, $filename);
      my $tmppathname  = join($DIRSEP, $OUTDIR, "msgtmp.$$");
  
      if ($adding) {
! 	return ($i_p0, $filename)  unless $Update{$msgnum};
  	#&file_rename($filepathname, $tmppathname);
! 	eval {
! 	  $msginfh = file_open($filepathname);
! 	};
! 	if ($@) {
! 	  # Something is screwed up with archive: We try to delete
! 	  # message from database since message file appears to have
! 	  # disappeared
! 	  warn $@,
! 	       qq/...Will attempt to remove message and continue on\n/;
! 	  delmsg($index);
! 
! 	  # Nothing else to do, so return.
! 	  return;
! 	}
      }
      if ($SINGLE) {
***************
*** 1245,1248 ****
--- 1294,1302 ----
  	    file_utime($tmp, $tmp, @array2);
  	};
+ 	if ($@) {
+ 	    warn qq/\nWarning: Your platform does not support setting file/,
+ 		   qq/         modification times\n/;
+ 	    $MODTIME = 0;
+ 	}
      }
  
***************
*** 1295,1299 ****
  	defined($IndexNum{$MsgId{$refmsgid}}) &&
  	(!$onlynew || $NewMsgId{$refmsgid})) {
! 	local($lreftmpl) = $MSGIDLINK;
  	$lreftmpl =~ s/$VarExp/&replace_li_var($1,$MsgId{$refmsgid})/geo;
  	$lreftmpl;
--- 1349,1353 ----
  	defined($IndexNum{$MsgId{$refmsgid}}) &&
  	(!$onlynew || $NewMsgId{$refmsgid})) {
! 	my($lreftmpl) = $MSGIDLINK;
  	$lreftmpl =~ s/$VarExp/&replace_li_var($1,$MsgId{$refmsgid})/geo;
  	$lreftmpl;

---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-DEV