[LON-CAPA-cvs] cvs: loncom(Refactoring) / lond

foxr lon-capa-cvs@mail.lon-capa.org
Thu, 29 Apr 2004 10:35:07 -0000


foxr		Thu Apr 29 06:35:07 2004 EDT

  Modified files:              (Branch: Refactoring)
    /loncom	lond 
  Log:
  I liked the logic for sub unsub I put into the main branch better than the
  hack job I put in here ... so transplant.
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.178.2.20 loncom/lond:1.178.2.21
--- loncom/lond:1.178.2.20	Tue Apr 27 07:30:28 2004
+++ loncom/lond	Thu Apr 29 06:35:07 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.178.2.20 2004/04/27 11:30:28 foxr Exp $
+# $Id: lond,v 1.178.2.21 2004/04/29 10:35:07 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,7 +53,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.178.2.20 $'; #' stupid emacs
+my $VERSION='$Revision: 1.178.2.21 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
@@ -1028,7 +1028,7 @@
    
     my $userinput = "$cmd:$tail";
    
-    my $fname=split(/:/$tail);	# This allows interactive testing
+    my $fname=split(/:/,$tail);	# This allows interactive testing
     chomp($fname);		# with telnet.
 
     my $ownership=ishome($fname);
@@ -4388,25 +4388,36 @@
 sub unsub {
     my ($fname,$clientip)=@_;
     my $result;
-#    if (unlink("$fname.$clientname")) {
-#	$result="ok\n";
-#    } else {
-#	$result="not_subscribed\n";
-#    }
-    unlink("$fname.$clientname");
+    my $unsubs = 0;		# Number of successful unsubscribes:
+
+
+    # An old way subscriptions were handled was to have a 
+    # subscription marker file:
+
+    Debug("Attempting unlink of $fname.$clientname");
+    if (unlink("$fname.$clientname")) {
+	$unsubs++;		# Successful unsub via marker file.
+    } 
+
+    # The more modern way to do it is to have a subscription list
+    # file:
+
     if (-e "$fname.subscription") {
-	Debug ("Processing subscription file $fname.subscription");
 	my $found=&addline($fname,$clientname,$clientip,'');
 	if ($found) { 
-	    Debug("Old linek found");
-	    $result="ok\n"; 
-	} else {
-	    $result = "not_subscribed\n";
+	    $unsubs++;
 	}
+    } 
+
+    #  If either or both of these mechanisms succeeded in unsubscribing a 
+    #  resource we can return ok:
+
+    if($unsubs) {
+	$result = "ok\n";
     } else {
-	Debug("No Subscription file $fname.subscription");
-	if ($result ne "ok\n") { $result="not_subscribed\n"; }
+	$result = "not_subscribed\n";
     }
+
     return $result;
 }