[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm /publisher lonpublisher.pm

www lon-capa-cvs-allow@mail.lon-capa.org
Mon, 12 May 2008 20:59:22 -0000


www		Mon May 12 16:59:22 2008 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/publisher	lonpublisher.pm 
  Log:
  Work on locks.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.957 loncom/lonnet/perl/lonnet.pm:1.958
--- loncom/lonnet/perl/lonnet.pm:1.957	Wed Apr 30 18:42:59 2008
+++ loncom/lonnet/perl/lonnet.pm	Mon May 12 16:59:15 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.957 2008/04/30 22:42:59 raeburn Exp $
+# $Id: lonnet.pm,v 1.958 2008/05/12 20:59:15 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -39,7 +39,7 @@
 my (%badServerCache, $memcache, %courselogs, %accesshash, %domainrolehash,
     %userrolehash, $processmarker, $dumpcount, %coursedombuf,
     %coursenumbuf, %coursehombuf, %coursedescrbuf, %courseinstcodebuf,
-    %courseownerbuf, %coursetypebuf);
+    %courseownerbuf, %coursetypebuf,$locknum);
 
 use IO::Socket;
 use GDBM_File;
@@ -526,6 +526,51 @@
     return(@values);
 }
 
+# ------------------------------------------------------------------- Locking
+
+sub set_lock {
+    my ($text)=@_;
+    $locknum++;
+    my $id=$$.'-'.$locknum;
+    &appenv({'session.locks' => $env{'session.locks'}.','.$id,
+             'session.lock.'.$id => $text});
+    return $id;
+}
+
+sub get_locks {
+    my $num=0;
+    my %texts=();
+    foreach my $lock (split(/\,/,$env{'session.locks'})) {
+       if ($lock=~/\w/) {
+          $num++;
+          $texts{$lock}=$env{'session.lock.'.$lock};
+       }
+   }
+   return ($num,%texts);
+}
+
+sub remove_lock {
+    my ($id)=@_;
+    my $newlocks='';
+    foreach my $lock (split(/\,/,$env{'session.locks'})) {
+       if (($lock=~/\w/) && ($lock ne $id)) {
+          $newlocks.=','.$lock;
+       }
+    }
+    &appenv({'session.locks' => $newlocks});
+    &delenv('session.lock.'.$id);
+}
+
+sub remove_all_locks {
+    my $activelocks=$env{'session.locks'};
+    foreach my $lock (split(/\,/,$env{'session.locks'})) {
+       if ($lock=~/\w/) {
+          &remove_lock($lock);
+       }
+    }
+}
+
+
 # ------------------------------------------ Find out current server userload
 sub userload {
     my $numusers=0;
@@ -8763,6 +8808,7 @@
 
 $processmarker='_'.time.'_'.$perlvar{'lonHostID'};
 $dumpcount=0;
+$locknum=0;
 
 &logtouch();
 &logthis('<font color="yellow">INFO: Read configuration</font>');
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.232 loncom/publisher/lonpublisher.pm:1.233
--- loncom/publisher/lonpublisher.pm:1.232	Tue Mar 18 19:31:31 2008
+++ loncom/publisher/lonpublisher.pm	Mon May 12 16:59:22 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.232 2008/03/18 23:31:31 raeburn Exp $
+# $Id: lonpublisher.pm,v 1.233 2008/05/12 20:59:22 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -143,6 +143,8 @@
 my $registered_cleanup;
 my $modified_urls;
 
+my $lock;
+
 =pod
 
 =item B<metaeval>
@@ -1744,6 +1746,7 @@
 	print $logfile "\n============ Done ============\n";
 	$logfile->close();
     }
+    if ($lock) { &Apache::lonnet::remove_lock($lock); }
     return OK;
 }
 
@@ -1813,7 +1816,9 @@
                   &checkbox('obsolete','make file(s) obsolete').
 		  &checkbox('forceoverride','force directory level catalog information over existing').
 		  '<br /><input type="submit" value="'.&mt('Publish Directory').'" /></form>');
+        $lock=0;
     } else {
+        unless ($lock) { $lock=&Apache::lonnet::set_lock('Publishing '.$fn); }
 # actually publish things
 	opendir(DIR,$fn);
 	my @files=sort(readdir(DIR));