View | Details | Raw Unified | Return to bug 5612
Collapse All | Expand All

(-)Mail-SpamAssassin-3.2.3.patched/lib/Mail/SpamAssassin/Util.pm (-7 / +22 lines)
Lines 1559-1575 Link Here
1559
# be unable to open the database.  This workaround solves both problems. 
1559
# be unable to open the database.  This workaround solves both problems. 
1560
#
1560
#
1561
sub avoid_db_file_locking_bug {
1561
sub avoid_db_file_locking_bug {
1562
  my ($path) = @_;
1562
  my $path = shift;
1563
  
1564
  my $db_tmp_file = '__db.'.basename($path);
1565
  my $db_tmp_file_match = $db_tmp_file . '.';
1563
1566
1564
  my $parentdir = dirname($path);
1567
  my $parentdir = dirname($path);
1565
  my $db_tmpfile = File::Spec->catfile($parentdir,'__db.'.basename($path));
1566
1568
1567
  if (-e $db_tmpfile) {
1569
  # The db bug is actually more pervasive then orignally thought we can also have __db.[DBNAME].* as well.
1568
    dbg("Berkeley DB bug work-around: cleaning tmp file $db_tmpfile");
1570
1569
    if (!unlink($db_tmpfile)) {
1571
  opendir(my $sa_db_dir_fh, $parentdir);
1570
      die "cannot remove Berkeley DB tmp file $db_tmpfile: $!\n";
1572
  while(my $test_filename = readdir($sa_db_dir_fh)) {  
1571
    }
1573
	# If the file is __db.[DBNAME] or the file is __db.[DBNAME].* (glob) then we need to remove it
1574
	# we use substr here as its slightly fater then using a regex 
1575
1576
	my $newtest = substr($test_filename,0,length($db_tmp_file_match));
1577
1578
	if ( substr($test_filename,0,length($db_tmp_file_match)) eq $db_tmp_file_match || $test_filename eq $db_tmp_file ) {
1579
		my $db_tmpfile = untaint_file_path( File::Spec->catfile($parentdir,$test_filename) );
1580
		
1581
		dbg("Berkeley DB bug work-around: cleaning tmp file $db_tmpfile");
1582
		if (!unlink($db_tmpfile)) {
1583
			die "cannot remove Berkeley DB tmp file $db_tmpfile: $!\n";
1584
		}
1585
	}
1572
  }
1586
  }
1587
  closedir($sa_db_dir_fh);
1573
}
1588
}
1574
1589
1575
###########################################################################
1590
###########################################################################

Return to bug 5612