[LON-CAPA-cvs] cvs: loncom /cgi decompress.pl

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 09 Jun 2004 19:04:47 -0000


albertel		Wed Jun  9 15:04:47 2004 EDT

  Modified files:              
    /loncom/cgi	decompress.pl 
  Log:
  - large number of roles would blow up the system call. (BUG#3044)
  
  
Index: loncom/cgi/decompress.pl
diff -u loncom/cgi/decompress.pl:1.11 loncom/cgi/decompress.pl:1.12
--- loncom/cgi/decompress.pl:1.11	Fri Dec 12 19:20:47 2003
+++ loncom/cgi/decompress.pl	Wed Jun  9 15:04:47 2004
@@ -32,6 +32,7 @@
 use strict;
 use lib '/home/httpd/lib/perl';
 use LONCAPA::loncgi ();
+my %origENV=%ENV;
 if(! &LONCAPA::loncgi::check_cookie_and_load_env()) {
     print "Content-type: text/html\n\n";
     print <<END;
@@ -39,7 +40,10 @@
 END
 } else {
     print "Content-type: text/html\n\n";
-    if(! $ENV{'cgi.file'} || ! $ENV{'cgi.dir'}) {
+    my $file=$ENV{'cgi.file'};
+    my $dir=$ENV{'cgi.dir'}; 
+    %ENV=%origENV;
+    if(! $file || ! $dir) {
         print <<END;
         <html><body>Bad Enviroment!</body></html>
 END
@@ -47,51 +51,51 @@
         print <<END;
 	<html><body><b>Output of decompress:</b><br /><br />
 END
-        chdir $ENV{'cgi.dir'};
-        if ($ENV{'cgi.file'} =~ m|\.zip$|i) {
-            open(OUTPUT, "unzip -o $ENV{'cgi.file'} 2> /dev/null |");
+        chdir $dir;
+        if ($file =~ m|zip|) {
+            open(OUTPUT, "unzip $file 2> /dev/null |");
             while (<OUTPUT>) {
                 print "$_<br />";
             }
             close(OUTPUT);
-        } elsif ($ENV{'cgi.file'} =~ m|\.tar\.gz$|i) {
-            open(OUTPUT, "tar -zxpvf $ENV{'cgi.file'} 2> /dev/null |");
+        } elsif ($file =~ m|tar.gz|) {
+            open(OUTPUT, "tar -zxpvf $file 2> /dev/null |");
             while (<OUTPUT>) {
                 print "$_<br />";
             }
             close(OUTPUT);
-        } elsif ($ENV{'cgi.file'} =~ m|\.tar\.bz2$|i) {
-            open(OUTPUT, "tar -jxpvf $ENV{'cgi.file'} 2> /dev/null |");
+        } elsif ($file =~ m|tar.bz2|) {
+            open(OUTPUT, "tar -jxpvf $file 2> /dev/null |");
             while (<OUTPUT>) {
                 print "$_<br />";
             }
             close(OUTPUT);
-        } elsif ($ENV{'cgi.file'} =~ m|\.bz2$|i) {
-            open(OUTPUT, "bunzip2 $ENV{'cgi.file'} 2> /dev/null |");
+        } elsif ($file =~ m|bz2|) {
+            open(OUTPUT, "bunzip2 $file 2> /dev/null |");
             while (<OUTPUT>) {
                 print "$_<br />";
             }
             close(OUTPUT);
-        } elsif ($ENV{'cgi.file'} =~ m|\.tgz$|i) {
-            open(OUTPUT, "tar -zxpvf $ENV{'cgi.file'} 2> /dev/null |");
+        } elsif ($file =~ m|tgz|) {
+            open(OUTPUT, "tar -zxpvf $file 2> /dev/null |");
             while (<OUTPUT>) {
                 print "$_<br />";
             }
             close(OUTPUT);
-        } elsif ($ENV{'cgi.file'} =~ m|\.gz$|i) {
-            open(OUTPUT, "gunzip $ENV{'cgi.file'} 2> /dev/null |");
+        } elsif ($file =~ m|gz|) {
+            open(OUTPUT, "gunzip $file 2> /dev/null |");
             while (<OUTPUT>) {
                 print "$_<br />";
             }
             close(OUTPUT);
-        } elsif ($ENV{'cgi.file'} =~ m|\.tar$|i) {
-            open(OUTPUT, "tar -xpvf $ENV{'cgi.file'} 2> /dev/null |");
+        } elsif ($file =~ m|tar|) {
+            open(OUTPUT, "tar -xpvf $file 2> /dev/null |");
             while (<OUTPUT>) {
                 print "$_<br />";
             }
             close(OUTPUT);
         } else {
-            print "There has been an error in determining the file type of $ENV{'cgi.file'}, please check name";
+            print "There has been an error in determining the file type of $file, please check name";
         }
         print "<br /><b>Decompress complete!</b><br /></body></html>";
     }