--- loncom/publisher/loncfile.pm 2002/05/24 05:11:40 1.9 +++ loncom/publisher/loncfile.pm 2002/06/07 01:35:48 1.11 @@ -10,7 +10,7 @@ # # -# $Id: loncfile.pm,v 1.9 2002/05/24 05:11:40 foxr Exp $ +# $Id: loncfile.pm,v 1.11 2002/06/07 01:35:48 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -63,8 +63,8 @@ use Apache::Constants qw(:common :http : use Apache::loncacc; use Apache::Log (); -my $DEBUG=1; - +my $DEBUG=0; +my $r; # Needs to be global for some stuff RF. # # Debug # If debugging is enabled puts out a debuggin message determined by the @@ -83,7 +83,26 @@ sub Debug { $log->debug($message); } } - +# +# URLToPath +# Convert a URL to a file system path. +# +# In order to manipulate the construction space objects, it's necessary +# to access url identified objects a filespace objects. This function +# translates a construction space URL to a file system path. +# Parameters: +# Url - string [in] The url to convert. +# Returns: +# The corresponing file system path. +sub URLToPath +{ + my $Url = shift; + &Debug($r, "UrlToPath got: $Url"); + $Url=~ s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/; + $Url=~ s/^http\:\/\/[^\/]+//; + &Debug($r, "Returning $Url \n"); + return $Url; +} sub exists { my ($uname,$udom,$dir,$newfile)=@_; my $published='/home/httpd/html/res/'.$udom.'/'.$uname.'/'.$dir.'/'. @@ -120,7 +139,12 @@ sub phaseone { my $main=$2; my $suffix=$3; - my $conspace='/home/'.$uname.'/public_html'.$fn; + my $conspace; + if ($fn =~ m-^/home/-) { + $conspace=$fn; + } else { + $conspace='/home/'.$uname.'/public_html'.$fn; + } $r->print('
'. ''. @@ -196,6 +220,7 @@ sub phasetwo { my $dir=$1; my $main=$2; my $suffix=$3; + $dir =~ s-^/[^/]*/[^/]*/[^/]*--; &Debug($r, "loncfile::phase2 dir = $dir main = $main suffix = $suffix"); @@ -209,7 +234,7 @@ sub phasetwo { if ($ENV{'form.action'} eq 'rename') { if (-e $conspace) { if ($ENV{'form.newfilename'}) { - unless (rename('/home/'.$uname.'/public_html'.$fn, + unless (rename($fn, '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) { $r->print('Error: '.$!.''); } @@ -220,7 +245,7 @@ sub phasetwo { } } elsif ($ENV{'form.action'} eq 'delete') { if (-e $conspace) { - unless (unlink('/home/'.$uname.'/public_html'.$fn)) { + unless (unlink($fn)) { $r->print('Error: '.$!.''); } } else { @@ -230,7 +255,7 @@ sub phasetwo { } elsif ($ENV{'form.action'} eq 'copy') { if (-e $conspace) { if ($ENV{'form.newfilename'}) { - unless (copy('/home/'.$uname.'/public_html'.$fn, + unless (copy($fn, '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) { $r->print('Error: '.$!.''); } @@ -265,7 +290,7 @@ sub phasetwo { sub handler { - my $r=shift; + $r=shift; &Debug($r, "loncfile.pm - handler entered"); @@ -275,8 +300,9 @@ sub handler { if ($ENV{'form.filename'}) { $fn=$ENV{'form.filename'}; &Debug($r, "loncfile::handler - raw url: $fn"); - $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/; - $fn=~s/^http\:\/\/[^\/]+//; +# $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/; +# $fn=~s/^http\:\/\/[^\/]+//; + $fn=URLToPath($fn); &Debug($r, "loncfile::handler - doctored url: $fn"); } else {