version 1.132, 2009/11/15 14:08:53
|
version 1.137, 2011/04/21 13:28:50
|
Line 62 my %hiddenurl; # this URL (or complete f
|
Line 62 my %hiddenurl; # this URL (or complete f
|
|
|
# ----------------------------------- Remove version from URL and store in hash |
# ----------------------------------- Remove version from URL and store in hash |
|
|
|
sub versionerror { |
|
my ($uri,$usedversion,$unusedversion)=@_; |
|
return '<br />'.&mt('Version discrepancy: resource [_1] included in both version [_2] and version [_3]. Using version [_2].', |
|
$uri,$usedversion,$unusedversion).'<br />'; |
|
} |
|
|
sub versiontrack { |
sub versiontrack { |
my $uri=shift; |
my $uri=shift; |
if ($uri=~/\.(\d+)\.\w+$/) { |
if ($uri=~/\.(\d+)\.\w+$/) { |
Line 69 sub versiontrack {
|
Line 75 sub versiontrack {
|
$uri=~s/\.\d+\.(\w+)$/\.$1/; |
$uri=~s/\.\d+\.(\w+)$/\.$1/; |
unless ($hash{'version_'.$uri}) { |
unless ($hash{'version_'.$uri}) { |
$hash{'version_'.$uri}=$version; |
$hash{'version_'.$uri}=$version; |
} |
} elsif ($version!=$hash{'version_'.$uri}) { |
|
$errtext.=&versionerror($uri,$hash{'version_'.$uri},$version); |
|
} |
} |
} |
return $uri; |
return $uri; |
} |
} |
Line 118 sub loadmap {
|
Line 126 sub loadmap {
|
my $lpc=$pc; |
my $lpc=$pc; |
$hash{'map_pc_'.$uri}=$lpc; |
$hash{'map_pc_'.$uri}=$lpc; |
$hash{'map_id_'.$lpc}=$uri; |
$hash{'map_id_'.$lpc}=$uri; |
|
if ($parent_rid =~ /^(\d+)\.\d+$/) { |
|
my $parent_pc = $1; |
|
if (defined($hash{'map_hierarchy_'.$parent_pc})) { |
|
$hash{'map_hierarchy_'.$lpc}=$hash{'map_hierarchy_'.$parent_pc}.','. |
|
$parent_pc; |
|
} else { |
|
$hash{'map_hierarchy_'.$lpc}=$parent_pc; |
|
} |
|
} |
|
|
# Determine and check filename |
# Determine and check filename |
my $fn=&Apache::lonnet::filelocation('',&putinversion($uri)); |
my $fn=&Apache::lonnet::filelocation('',&putinversion($uri)); |
Line 278 sub parse_resource {
|
Line 295 sub parse_resource {
|
$hash{'ids_'.$idsuri}=''.$rid; |
$hash{'ids_'.$idsuri}=''.$rid; |
} |
} |
|
|
if ($turi=~/\/(syllabus|aboutme|navmaps|smppg|bulletinboard)$/) { |
if ($turi=~/\/(syllabus|aboutme|navmaps|smppg|bulletinboard|viewclasslist)$/) { |
$turi.='?register=1'; |
$turi.='?register=1'; |
} |
} |
|
|
Line 645 sub readmap {
|
Line 662 sub readmap {
|
my $uri; |
my $uri; |
$short=~s/\//\_/g; |
$short=~s/\//\_/g; |
unless ($uri=$cenv{'url'}) { |
unless ($uri=$cenv{'url'}) { |
&Apache::lonnet::logthis("<font color=blue>WARNING: ". |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
"Could not load course $short.</font>"); |
"Could not load course $short.</font>"); |
return ('',&mt('No course data available.'));; |
return ('',&mt('No course data available.'));; |
} |
} |
@cond=('true:normal'); |
@cond=('true:normal'); |
|
|
open(LOCKFILE,">$fn.db.lock"); |
unless (open(LOCKFILE,">$fn.db.lock")) { |
|
$errtext.='<br />'.&mt('Map not loaded - Lock file could not be opened when reading map:').' <tt>'.$fn.'</tt>.'; |
|
$retfurl = ''; |
|
return ($retfurl,$errtext); |
|
} |
my $lock=0; |
my $lock=0; |
my $gotstate=0; |
my $gotstate=0; |
if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) { |
if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) { |
Line 685 sub readmap {
|
Line 706 sub readmap {
|
} |
} |
} |
} |
flock(LOCKFILE,LOCK_UN); |
flock(LOCKFILE,LOCK_UN); |
close(LOCKFILE); |
|
} |
} |
unless ($lock && $tiedhash && $tiedparmhash) { |
unless ($lock && $tiedhash && $tiedparmhash) { |
# if we are here it is likely because we are already trying to |
# if we are here it is likely because we are already trying to |
Line 708 sub readmap {
|
Line 728 sub readmap {
|
untie(%parmhash); |
untie(%parmhash); |
} |
} |
} |
} |
&Apache::lonnet::logthis("<font color=blue>WARNING: ". |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
"Could not tie coursemap $fn for $uri.</font>"); |
"Could not tie coursemap $fn for $uri.</font>"); |
$tiedhash = ''; |
$tiedhash = ''; |
$tiedparmhash = ''; |
$tiedparmhash = ''; |
Line 740 sub readmap {
|
Line 760 sub readmap {
|
} |
} |
if ($lock) { |
if ($lock) { |
flock(LOCKFILE,LOCK_UN); |
flock(LOCKFILE,LOCK_UN); |
|
$lock = 0; |
if ($tiedparmhash) { |
if ($tiedparmhash) { |
unless ($untiedparmhash) { |
unless ($untiedparmhash) { |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
Line 755 sub readmap {
|
Line 776 sub readmap {
|
} |
} |
} |
} |
unless ($gotstate) { |
unless ($gotstate) { |
|
$lock = 0; |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
'Could not read statemap '.$fn.' for '.$uri.'.</font>'); |
'Could not read statemap '.$fn.' for '.$uri.'.</font>'); |
&unlink_tmpfiles($fn); |
&unlink_tmpfiles($fn); |
if (open(LOCKFILE,">$fn.db.lock")) { |
if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) { |
my $lock=0; |
$lock=1; |
if (flock(LOCKFILE,LOCK_EX|LOCK_NB)) { |
} |
$lock=1; |
undef %randompick; |
&unlink_tmpfiles($fn); |
undef %hiddenurl; |
} |
undef %encurl; |
undef %randompick; |
$retfrid=''; |
undef %hiddenurl; |
if ($lock) { |
undef %encurl; |
if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) { |
$retfrid=''; |
if (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640)) { |
if ($lock) { |
$gotstate = &build_tmp_hashes($uri,$fn,$short,\%cenv); |
if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) { |
unless ($gotstate) { |
if (tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640)) { |
|
$gotstate = &build_tmp_hashes($uri,$fn,$short,\%cenv); |
|
unless ($gotstate) { |
|
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
|
'Failed to write statemap at second attempt '.$fn.' for '.$uri.'.</font>'); |
|
} |
|
unless (untie(%parmhash)) { |
|
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
|
'Could not untie coursemap parmhash '.$fn.'.db for '.$uri.'.</font>'); |
|
} |
|
} else { |
|
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
'Could not tie coursemap '.$fn.'__parms.db for '.$uri.'.</font>'); |
'Failed to write statemap at second attempt '.$fn.' for '.$uri.'.</font>'); |
} |
} |
unless (untie(%hash)) { |
unless (untie(%parmhash)) { |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
'Could not untie coursemap hash '.$fn.'.db for '.$uri.'.</font>'); |
'Could not untie coursemap parmhash '.$fn.'.db for '.$uri.'.</font>'); |
} |
} |
} else { |
} else { |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
'Could not tie coursemap '.$fn.'.db for '.$uri.'.</font>'); |
'Could not tie coursemap '.$fn.'__parms.db for '.$uri.'.</font>'); |
} |
} |
flock(LOCKFILE,LOCK_UN); |
unless (untie(%hash)) { |
close(LOCKFILE); |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
|
'Could not untie coursemap hash '.$fn.'.db for '.$uri.'.</font>'); |
|
} |
} else { |
} else { |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
'Could not obtain lock to tie coursemap hash '.$fn.'.db for '.$uri.'.</font>'); |
'Could not tie coursemap '.$fn.'.db for '.$uri.'.</font>'); |
} |
} |
close(LOCKFILE); |
flock(LOCKFILE,LOCK_UN); |
|
$lock = 0; |
|
} else { |
|
&Apache::lonnet::logthis('<font color="blue">WARNING: '. |
|
'Could not obtain lock to tie coursemap hash '.$fn.'.db for '.$uri.'.</font>'); |
} |
} |
} |
} |
|
close(LOCKFILE); |
unless (($errtext eq '') || ($env{'request.course.uri'} =~ m{^/uploaded/})) { |
unless (($errtext eq '') || ($env{'request.course.uri'} =~ m{^/uploaded/})) { |
&Apache::lonmsg::author_res_msg($env{'request.course.uri'}, |
&Apache::lonmsg::author_res_msg($env{'request.course.uri'}, |
$errtext); |
$errtext); |
Line 888 sub build_tmp_hashes {
|
Line 906 sub build_tmp_hashes {
|
|
|
sub unlink_tmpfiles { |
sub unlink_tmpfiles { |
my ($fn) = @_; |
my ($fn) = @_; |
if ($fn =~ m{^\Q$Apache::lonnet::perlvar{'lonUsersDir'}\E/tmp/}) { |
if ($fn =~ m{^\Q$Apache::lonnet::perlvar{'lonDaemons'}\E/tmp/}) { |
my @files = qw (.db _symb.db .state _parms.db); |
my @files = qw (.db _symb.db .state _parms.db); |
foreach my $file (@files) { |
foreach my $file (@files) { |
if (-e $fn.$file) { |
if (-e $fn.$file) { |