--- loncom/debugging_tools/dump_db.pl 2005/03/18 21:36:49 1.5 +++ loncom/debugging_tools/dump_db.pl 2007/07/25 17:43:34 1.8 @@ -4,7 +4,7 @@ # # dump_db.pl - dump a GDBM database to standard output, unescaping if asked to. # -# $Id: dump_db.pl,v 1.5 2005/03/18 21:36:49 albertel Exp $ +# $Id: dump_db.pl,v 1.8 2007/07/25 17:43:34 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,6 +34,10 @@ use Getopt::Long; use GDBM_File; use Data::Dumper; use Storable qw(thaw); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; +use LONCAPA::Configuration; +use Cwd; # # Options @@ -64,15 +68,26 @@ END exit; } +my %perlvar=%{&LONCAPA::Configuration::read_conf('loncapa.conf')}; + # # Loop through ARGV getting files. while (my $fname = shift) { - my %db; - if (! tie(%db,'GDBM_File',$fname,&GDBM_READER(),0640)) { + $fname = &Cwd::abs_path($fname); + my $dbref; + if ($fname =~ m/^\Q$perlvar{'lonUsersDir'}\E/) { + $dbref=&LONCAPA::locking_hash_tie($fname,&GDBM_READER()); + } else { + if (tie(my %db,'GDBM_File',$fname,&GDBM_READER(),0640)) { + $dbref = \%db; + } + } + + if (!$dbref) { warn "Unable to tie to $fname"; next; } - while (my ($key,$value) = each(%db)) { + while (my ($key,$value) = each(%$dbref)) { if ($value =~ s/^__FROZEN__//) { $value = thaw(&unescape($value)); } @@ -85,13 +100,11 @@ while (my $fname = shift) { } print "$key = ".(ref($value)?Dumper($value):$value)."\n"; } - untie %db; + if ($fname =~ m/^\Q$perlvar{'lonUsersDir'}\E/) { + &LONCAPA::locking_hash_untie($dbref); + } else { + untie($dbref); + } } exit; -###################################### -sub unescape { - my $str=shift; - $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - return $str; -}