version 1.3, 2003/11/14 20:42:34
|
version 1.4, 2006/06/27 15:01:14
|
Line 2
|
Line 2
|
# |
# |
use strict; |
use strict; |
use GDBM_File; |
use GDBM_File; |
|
use lib '/home/httpd/lib/perl/'; |
sub unescape { |
use LONCAPA; |
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; |
|
} |
|
|
|
my %resourceaccess; |
my %resourceaccess; |
|
|
Line 22 sub main {
|
Line 12 sub main {
|
my $target = $ARGV[1]; |
my $target = $ARGV[1]; |
my ($owner) = ($target =~ m:.*/(.*)/nohist_accesscount.db:); |
my ($owner) = ($target =~ m:.*/(.*)/nohist_accesscount.db:); |
print STDERR "source: $file\ntarget: $target\nowner: $owner\n"; |
print STDERR "source: $file\ntarget: $target\nowner: $owner\n"; |
my %accessDB; |
|
my $accesstime = 0; |
my $accesstime = 0; |
my $starttime = time; |
my $starttime = time; |
if (-e $target) { |
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"; |
warn "Unable to tie to $target"; |
return; |
return; |
} |
} |
# |
# |
if (exists($accessDB{'tabulated '.$file})) { |
if (exists($accessDB->{'tabulated '.$file})) { |
$accesstime = $accessDB{'tabulated '.$file}; |
$accesstime = $accessDB->{'tabulated '.$file}; |
} |
} |
untie(%accessDB); |
&LONCAPA::locking_hash_untie($accessDB); |
} |
} |
# |
# |
my $line; |
my $line; |
Line 84 sub main {
|
Line 74 sub main {
|
} |
} |
} |
} |
print STDERR 'done. Updating '.$target.$/; |
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".$/; |
warn "Unable to open $target to store data".$/; |
return; |
return; |
} |
} |
# |
# |
while (my ($resource,$count) = each(%resourceaccess)) { |
while (my ($resource,$count) = each(%resourceaccess)) { |
$resource = &escape($resource); |
$resource = &escape($resource); |
if (exists($accessDB{$resource})) { |
if (exists($accessDB->{$resource})) { |
$accessDB{$resource}+=$count; |
$accessDB->{$resource}+=$count; |
} else { |
} else { |
$accessDB{$resource} = $count; |
$accessDB->{$resource} = $count; |
} |
} |
print sprintf("%10.0f",$count).':'.$resource."\n"; |
print sprintf("%10.0f",$count).':'.$resource."\n"; |
} |
} |
$accessDB{'tabulated '.$file} = $starttime; |
$accessDB->{'tabulated '.$file} = $starttime; |
untie(%accessDB); |
&LONCAPA::locking_hash_untie($accessDB); |
} |
} |
|
|
main; |
main; |