--- loncom/debugging_tools/activity_to_accesscount.pl 2003/11/14 20:42:34 1.3 +++ loncom/debugging_tools/activity_to_accesscount.pl 2006/06/27 15:01:14 1.4 @@ -2,18 +2,8 @@ # use strict; use GDBM_File; - -sub unescape { - my $str=shift; - $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - return $str; -} - -sub escape { - my $str=shift; - $str =~ s/(\W)/"%".unpack('H2',$1)/eg; - return $str; -} +use lib '/home/httpd/lib/perl/'; +use LONCAPA; my %resourceaccess; @@ -22,19 +12,19 @@ sub main { my $target = $ARGV[1]; my ($owner) = ($target =~ m:.*/(.*)/nohist_accesscount.db:); print STDERR "source: $file\ntarget: $target\nowner: $owner\n"; - my %accessDB; my $accesstime = 0; my $starttime = time; if (-e $target) { - if (! tie(%accessDB,'GDBM_File',$target,&GDBM_READER,0640)) { + my $accessDB = &LONCAPA::locking_hash_tie($target,&GDBM_READER()); + if (! $accessDB) { warn "Unable to tie to $target"; return; } # - if (exists($accessDB{'tabulated '.$file})) { - $accesstime = $accessDB{'tabulated '.$file}; + if (exists($accessDB->{'tabulated '.$file})) { + $accesstime = $accessDB->{'tabulated '.$file}; } - untie(%accessDB); + &LONCAPA::locking_hash_untie($accessDB); } # my $line; @@ -84,22 +74,24 @@ sub main { } } print STDERR 'done. Updating '.$target.$/; - if (! tie(%accessDB,'GDBM_File',$target,&GDBM_WRCREAT,0640)) { + + my $accessDB = &LONCAPA::locking_hash_tie($target,&GDBM_WRCREAT()); + if (! $accessDB) { warn "Unable to open $target to store data".$/; return; } # while (my ($resource,$count) = each(%resourceaccess)) { $resource = &escape($resource); - if (exists($accessDB{$resource})) { - $accessDB{$resource}+=$count; + if (exists($accessDB->{$resource})) { + $accessDB->{$resource}+=$count; } else { - $accessDB{$resource} = $count; + $accessDB->{$resource} = $count; } print sprintf("%10.0f",$count).':'.$resource."\n"; } - $accessDB{'tabulated '.$file} = $starttime; - untie(%accessDB); + $accessDB->{'tabulated '.$file} = $starttime; + &LONCAPA::locking_hash_untie($accessDB); } main;