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

banghart lon-capa-cvs@mail.lon-capa.org
Mon, 25 Apr 2005 17:18:16 -0000


banghart		Mon Apr 25 13:18:16 2005 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  	Changes to mark_as_readonly, and unmark_as_readonly. Still needs testing.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.628 loncom/lonnet/perl/lonnet.pm:1.629
--- loncom/lonnet/perl/lonnet.pm:1.628	Fri Apr 22 17:01:25 2005
+++ loncom/lonnet/perl/lonnet.pm	Mon Apr 25 13:18:15 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.628 2005/04/22 21:01:25 albertel Exp $
+# $Id: lonnet.pm,v 1.629 2005/04/25 17:18:15 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3757,7 +3757,6 @@
     my %current_permissions = &dump('file_permissions',$domain,$user);
     my ($tmp)=keys(%current_permissions);
     if ($tmp=~/^error:/) { undef(%current_permissions); }
-
     foreach my $file (@{$files}) {
         push(@{$current_permissions{$file}},$what);
     }
@@ -3836,17 +3835,21 @@
 
 #--------------------------------------------------------------Get Marked as Read Only
 
+
 sub get_marked_as_readonly {
     my ($domain,$user,$what) = @_;
     my %current_permissions = &dump('file_permissions',$domain,$user);
     my ($tmp)=keys(%current_permissions);
     if ($tmp=~/^error:/) { undef(%current_permissions); }
-
     my @readonly_files;
+    my $cmp1=$what;
+    if (ref($what)) { $cmp1=join('',@{$what}) };
     while (my ($file_name,$value) = each(%current_permissions)) {
         if (ref($value) eq "ARRAY"){
             foreach my $stored_what (@{$value}) {
-                if ($stored_what eq $what) {
+                my $cmp2=$stored_what;
+                if (ref($stored_what)) { $cmp2=join('',@{$stored_what}) };
+                if ($cmp1 eq $cmp2) {
                     push(@readonly_files, $file_name);
                 } elsif (!defined($what)) {
                     push(@readonly_files, $file_name);
@@ -3881,13 +3884,13 @@
 # ------------------------------------------------------------ Unmark as Read Only
 
 sub unmark_as_readonly {
-    # unmarks all files locked by $what 
-    # for portfolio submissions, $what contains $crsid and $symb
-    my ($domain,$user,$what) = @_;
+    # unmarks $file_name (if $file_name is defined), or all files locked by $what 
+    # for portfolio submissions, $what contains [$symb,$crsid] 
+    my ($domain,$user,$what,$file_name) = @_;
+    my $symb_crs = join('',@$what);
     my %current_permissions = &dump('file_permissions',$domain,$user);
     my ($tmp)=keys(%current_permissions);
     if ($tmp=~/^error:/) { undef(%current_permissions); }
-
     my @readonly_files = &get_marked_as_readonly($domain,$user,$what);
     foreach my $file(@readonly_files){
         my $current_locks = $current_permissions{$file};
@@ -3895,7 +3898,12 @@
         my @del_keys;
         if (ref($current_locks) eq "ARRAY"){
             foreach my $locker (@{$current_locks}) {
-                unless ($locker eq $what) {
+                &logthis("$$locker[0].$$locker[1] eq $symb_crs");
+                if ($$locker[0].$$locker[1] eq $symb_crs) {
+                    if (defined($file_name) && ($file_name ne $file)) {
+                        push(@new_locks, $what);
+                    }
+                } else {
                     push(@new_locks, $what);
                 }
             }
@@ -5324,6 +5332,7 @@
 
 sub getfile {
     my ($file) = @_;
+    &Apache::lonnet::logthis("file name is $file");
     if ($file =~ m -^/*(uploaded|editupload)/-) { $file=&filelocation("",$file); }
     &repcopy($file);
     return &readfile($file);