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

www lon-capa-cvs@mail.lon-capa.org
Thu, 03 Oct 2002 15:02:23 -0000


www		Thu Oct  3 11:02:23 2002 EDT

  Modified files:              
    /loncom	lond 
    /loncom/publisher	lonpublisher.pm 
  Log:
  Fixes Bug #111, toward Bug #531
  Can now explicitly address current version of a resource, not just previous
  ones.
  
  Does so by generating a symbolic link from the "versioned" filename to the
  current file. Deletes symbolic link again when file is republished, and
  subsequently replaces it by the now-stale "real" file.
  
  
Index: loncom/lond
diff -u loncom/lond:1.100 loncom/lond:1.101
--- loncom/lond:1.100	Mon Sep 30 17:38:18 2002
+++ loncom/lond	Thu Oct  3 11:02:22 2002
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.100 2002/09/30 21:38:18 matthew Exp $
+# $Id: lond,v 1.101 2002/10/03 15:02:22 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1647,12 +1647,63 @@
     return $result;
 }
 
+sub currentversion {
+    my $fname=shift;
+    my $version=-1;
+    my $ulsdir='';
+    if ($fname=~/^(.+)\/[^\/]+$/) {
+       $ulsdir=$1;
+    }
+    $fname=~s/\.\d+\.(\w+(?:\.meta)*)$/\.$1/;
+    $fname=~s/\.(\w+)$/\.\(\\d\+\)\.$1\$/;
+    if (-e $fname) { $version=1; }
+    if (-e $ulsdir) {
+       if(-d $ulsdir) {
+          if (opendir(LSDIR,$ulsdir)) {
+             while ($ulsfn=readdir(LSDIR)) {
+# see if this is a regular file (ignore links produced earlier)
+                 my $thisfile=$ulsdir.'/'.$ulsfn;
+                 unless (-l $thisfile) {
+		    if ($thisfile=~/$fname/) {
+		        if ($1>$version) { $version=$1; }
+                    }
+		 }
+             }
+             closedir(LSDIR);
+             $version++;
+          }
+      }
+   }
+   return $version;
+}
+
+sub thisversion {
+    my $fname=shift;
+    my $version=-1;
+    if ($fname=~/\.(\d+)\.\w+(?:\.meta)*$/) {
+	$version=$1;
+    }
+    return $version;
+}
+
 sub subscribe {
     my ($userinput,$clientip)=@_;
     my $result;
     my ($cmd,$fname)=split(/:/,$userinput);
     my $ownership=&ishome($fname);
     if ($ownership eq 'owner') {
+# explitly asking for the current version?
+        unless (-e $fname) {
+            my $currentversion=&currentversion($fname);
+	    if (&thisversion($fname)==$currentversion) {
+                if ($fname=~/^(.+)\.\d+\.(\w+(?:\.meta)*)$/) {
+		    my $root=$1;
+                    my $extension=$2;
+                    symlink($root.'.'.$extension,
+                            $root.'.'.$currentversion.'.'.$extension);
+                }
+            }
+        }
 	if (-e $fname) {
 	    if (-d $fname) {
 		$result="directory\n";
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.97 loncom/publisher/lonpublisher.pm:1.98
--- loncom/publisher/lonpublisher.pm:1.97	Wed Sep 18 11:43:06 2002
+++ loncom/publisher/lonpublisher.pm	Thu Oct  3 11:02:22 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.97 2002/09/18 15:43:06 www Exp $
+# $Id: lonpublisher.pm,v 1.98 2002/10/03 15:02:22 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -469,7 +469,8 @@
     while ($filename=readdir(DIR)) {
 	if ($filename=~/$srcf\.(\w+)$/) {
 	    my $subhost=$1;
-	    if ($subhost ne 'meta' && $subhost ne 'subscription') {
+	    if (($subhost ne 'meta' && $subhost ne 'subscription') &&
+                ($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {
 		push(@subscribed,$subhost);
 	    }
 	}
@@ -480,7 +481,11 @@
 	&Apache::lonnet::logthis("opened $target.subscription");
 	while (my $subline=<$sh>) {
 	    &Apache::lonnet::logthis("Trying $subline");
-	    if ($subline =~ /(^\w+):/) { push(@subscribed,$1); } else {
+	    if ($subline =~ /(^\w+):/) { 
+                if ($1 ne $Apache::lonnet::perlvar{'lonHostID'}) { 
+                   push(@subscribed,$1);
+	        }
+            } else {
 		&Apache::lonnet::logthis("No Match for $subline");
 	    }
 	}
@@ -1302,9 +1307,13 @@
     }
     opendir(DIR,$srcd);
     while ($filename=readdir(DIR)) {
+      if (-l $srcd.'/'.$filename) {
+       unlink($srcd.'/'.$filename);
+      } else {
        if ($filename=~/$srcf\.(\d+)\.$srct$/) {
 	   $maxversion=($1>$maxversion)?$1:$maxversion;
        }
+      }
     }
     closedir(DIR);
     $maxversion++;