--- loncom/cgi/decompress.pl 2005/05/25 22:31:51 1.14 +++ loncom/cgi/decompress.pl 2006/05/05 21:07:19 1.16 @@ -33,9 +33,19 @@ use strict; use lib '/home/httpd/lib/perl'; use LONCAPA::loncgi; -if(! &LONCAPA::loncgi::check_cookie_and_load_env()) { - print "Content-type: text/html\n\n"; - print <NO COOKIE! END } else { @@ -43,60 +53,43 @@ END my $file=$Apache::lonnet::env{'cgi.file'}; my $dir=$Apache::lonnet::env{'cgi.dir'}; if(! $file || ! $dir) { - print <Bad Enviroment! END } else { - print <Output of decompress:

+ print(<

Output of decompress:

END - chdir $dir; - if ($file =~ m|zip|) { - open(OUTPUT, "unzip $file 2> /dev/null |"); - while () { - print "$_
"; - } - close(OUTPUT); - } elsif ($file =~ m|tar.gz|) { - open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); - while () { - print "$_
"; - } - close(OUTPUT); - } elsif ($file =~ m|tar.bz2|) { - open(OUTPUT, "tar -jxpvf $file 2> /dev/null |"); - while () { - print "$_
"; - } - close(OUTPUT); - } elsif ($file =~ m|bz2|) { - open(OUTPUT, "bunzip2 $file 2> /dev/null |"); - while () { - print "$_
"; - } - close(OUTPUT); - } elsif ($file =~ m|tgz|) { - open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); - while () { - print "$_
"; - } - close(OUTPUT); - } elsif ($file =~ m|gz|) { - open(OUTPUT, "gunzip $file 2> /dev/null |"); - while () { - print "$_
"; - } - close(OUTPUT); - } elsif ($file =~ m|tar|) { - open(OUTPUT, "tar -xpvf $file 2> /dev/null |"); - while () { - print "$_
"; - } - close(OUTPUT); + chdir($dir); + my @cmd; + if ($file =~ m|\.zip$|) { + @cmd = ($location_of{'unzip'},"-o"); + } elsif ($file =~ m|\.tar\.gz$| + || $file =~ m|\.tgz$| ) { + @cmd = ($location_of{'tar'},"-zxpvf"); + } elsif ($file =~ m|\.tar\.bz2$|) { + @cmd = ($location_of{'tar'},"-jxpvf"); + } elsif ($file =~ m|\.bz2$|) { + @cmd = ($location_of{'bunzip2'}); + } elsif ($file =~ m|\.gz$|) { + @cmd = ($location_of{'gunzip'}); + } elsif ($file =~ m|\.tar$|) { + @cmd = ($location_of{'tar'},"-xpvf"); } else { - print "There has been an error in determining the file type of $file, please check name"; + print("There has been an error in determining the file type of $file, please check name"); } - print "
Decompress complete!
"; + if (@cmd) { + undef($!); + undef($@); + open(OUTPUT,"-|", @cmd, $file); + while (my $line = ) { print("$line
"); } + close(OUTPUT); + print("

Decompress complete.

"); + if ($! || $@) { + print("

An error occurred

$!

$@

"); + } + print(""); + } } }