[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm

banghart lon-capa-cvs@mail.lon-capa.org
Wed, 08 Sep 2004 17:53:38 -0000


banghart		Wed Sep  8 13:53:38 2004 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  
  	Disk quota enforced for portfolio. Currently hard-coded at 
  	20000k (20 meg).
  
  	Also added Fixme messages for expensive routines that need to be
  	re-worked.
  
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.37 loncom/interface/portfolio.pm:1.38
--- loncom/interface/portfolio.pm:1.37	Mon Sep  6 19:59:05 2004
+++ loncom/interface/portfolio.pm	Wed Sep  8 13:53:37 2004
@@ -376,10 +376,13 @@
 sub upload {
     my ($r)=@_;
     my $fname=$ENV{'form.uploaddoc.filename'};
+    my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
+    my $disk_quota = 20000; # expressed in k
     $fname=&Apache::lonnet::clean_filename($fname);
     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
 						 $ENV{'user.name'}).
 						'/userfiles/portfolio';
+    # Fixme --- Move the checking for existing file to LOND error return
     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
 					  $ENV{'user.domain'},
 					  $ENV{'user.name'},$portfolio_root);
@@ -390,8 +393,12 @@
             $found_file = 1;
         }
     }
-    $r->print('<br />'.&Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root).'<br />');
-    if ($found_file){   
+    my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
+    if (($current_disk_usage + $filesize) > $disk_quota){
+        $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
+                  '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
+    } 
+    elsif ($found_file){   
         $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'.
                   '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
     } else {
@@ -461,6 +468,7 @@
                                             ['selectfile','currentpath',
 					     'currentfile']);
 	# make sure there is a portfolio directory off /userfiles
+	# Fixme -- Do this in a better way -- offload it to the LOND routine
 	my @dir_list=&Apache::lonnet::dirlist('/',
 					    $ENV{'user.domain'},
 					    $ENV{'user.name'},$portfolio_root);
@@ -489,7 +497,7 @@
 	if ($ENV{'form.currentpath'}) {
 	    $current_path = $ENV{'form.currentpath'};
 	}
-	my @dir_list=&Apache::lonnet::dirlist($current_path,
+	@dir_list=&Apache::lonnet::dirlist($current_path,
 					    $ENV{'user.domain'},
 					    $ENV{'user.name'},$portfolio_root);