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

banghart lon-capa-cvs@mail.lon-capa.org
Mon, 08 Nov 2004 18:04:17 -0000


banghart		Mon Nov  8 13:04:17 2004 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  	unmark_as_readonly now seems to work, needs testing for
  	condition where a file is locked by multiple 
  	problem/course combinations.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.562 loncom/lonnet/perl/lonnet.pm:1.563
--- loncom/lonnet/perl/lonnet.pm:1.562	Fri Nov  5 20:11:38 2004
+++ loncom/lonnet/perl/lonnet.pm	Mon Nov  8 13:04:17 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.562 2004/11/06 01:11:38 albertel Exp $
+# $Id: lonnet.pm,v 1.563 2004/11/08 18:04:17 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3798,12 +3798,18 @@
 sub get_marked_as_readonly {
     my ($domain,$user,$what) = @_;
     my %current_permissions = &Apache::lonnet::dump('file_permissions',$domain,$user);
-    my @readonly_files = [];
-    while ((my $file_name, my $value) = each %current_permissions) {
+    my @readonly_files;
+    while (my ($file_name,$value) = each(%current_permissions)) {
+        &logthis("found $file_name");
         if (ref($value) eq "ARRAY"){
+            &logthis("found array");
             foreach my $stored_what (@{$value}) {
                 if ($stored_what eq $what) {
                     push(@readonly_files, $file_name);
+                    &logthis("defined pushed $file_name");
+                } elsif (!defined($what)) {
+                    push(@readonly_files, $file_name);
+                    &logthis("undef pushed $file_name");
                 }
             }
         } 
@@ -3820,7 +3826,23 @@
     my %current_permissions = &Apache::lonnet::dump('file_permissions',$domain,$user);
     my @readonly_files = &Apache::lonnet::get_marked_as_readonly($domain,$user,$what);
     foreach my $file(@readonly_files){
-        
+        my $current_locks = $current_permissions{$file};
+        my @new_locks;
+        my @del_keys;
+        if (ref($current_locks) eq "ARRAY"){
+            foreach my $locker (@{$current_locks}) {
+                unless ($locker eq $what) {
+                    push(@new_locks, $what);
+                }
+            }
+            if (@new_locks > 0) {
+                $current_permissions{$file} = \@new_locks;
+            } else {
+                push(@del_keys, $file);
+                &Apache::lonnet::del('file_permissions',\@del_keys, $domain, $user);
+                delete $current_permissions{$file};
+            }
+        }
     }
     &Apache::lonnet::put('file_permissions',\%current_permissions,$domain,$user);
     return;