--- loncom/debugging_tools/clean_db.pl 2005/03/18 21:36:49 1.2 +++ loncom/debugging_tools/clean_db.pl 2008/08/16 14:36:09 1.5 @@ -4,7 +4,7 @@ # # dump_db.pl - dump a GDBM database to standard output, unescaping if asked to. # -# $Id: clean_db.pl,v 1.2 2005/03/18 21:36:49 albertel Exp $ +# $Id: clean_db.pl,v 1.5 2008/08/16 14:36:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,6 +32,8 @@ use strict; use Getopt::Long; use GDBM_File; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; # # Options @@ -47,8 +49,6 @@ Specify the database filename on the com And the Key to remove. Options: --help Display this help. - --unescape Unescape the keys and values before printing them out. - -u Same as --unescape -t Localize times when possible (human readable times) Example: dump_db.pl mydata.db "error:" @@ -59,19 +59,19 @@ END my $fname = shift; my $key_to_remove = shift; -my %db; -if (! tie(%db,'GDBM_File',$fname,&GDBM_WRITER(),0640)) { - warn "Unable to tie to $fname"; +my $dbref =&LONCAPA::locking_hash_tie($fname,&GDBM_WRCREAT()); + +if (! $dbref) { + warn("Unable to tie to $fname"); exit; } -while (my ($key,$value) = each(%db)) { - if ($key ne $key_to_remove) { next; } - delete($db{$key}); +if (exists($dbref->{$key_to_remove})) { + delete($dbref->{$key_to_remove}); if ($fname =~ m|/nohist_[^/]*.db|) { exit; } my $hist=$fname; $hist=~s/\.db$/.hist/; open(HIST,">>$hist"); - print HIST "D:".time.":$key\n"; + print HIST ("D:".time.":$key_to_remove\n"); close(HIST); } exit;