--- loncom/publisher/loncfile.pm 2003/08/28 20:28:33 1.41
+++ loncom/publisher/loncfile.pm 2003/09/11 21:02:38 1.42
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.41 2003/08/28 20:28:33 matthew Exp $
+# $Id: loncfile.pm,v 1.42 2003/09/11 21:02:38 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -387,6 +387,10 @@ sub Rename1 {
if(-e $fn) {
if($newfilename) {
+ # is dest a dir
+ if (-d $newfilename) {
+ if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
+ }
if ($newfilename =~ m|/[^\.]+$|) {
#no extension add on original extension
if ($fn =~ m|/[^\.]*\.([^\.]+)$|) {
@@ -399,6 +403,10 @@ sub Rename1 {
if (-d $fn) {
$newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/;
}
+ $newfilename=~s://+:/:g; # remove duplicate /
+ while ($newfilename=~m:/\.\./:) {
+ $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
+ }
my $return=&exists($user, $domain, $newfilename);
$request->print($return);
if ($return =~/^Error:/) {
@@ -485,24 +493,36 @@ Parameters:
=cut
sub Copy1 {
- my ($request, $user, $domain, $fn, $newfilename) = @_;
+ my ($request, $user, $domain, $fn, $newfilename) = @_;
- if(-e $fn) {
- $request->print(&checksuffix($fn,$newfilename));
- my $return=&exists($user, $domain, $newfilename);
- $request->print($return);
- if ($return =~/^Error:/) {
- $request->print('
Cancel');
- return;
+ if(-e $fn) {
+ # is dest a dir
+ if (-d $newfilename) {
+ if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
+ }
+ if ($newfilename =~ m|/[^\.]+$|) {
+ #no extension add on original extension
+ if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; }
+ }
+ $newfilename=~s://+:/:g; # remove duplicate /
+ while ($newfilename=~m:/\.\./:) {
+ $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
+ }
+ $request->print(&checksuffix($fn,$newfilename));
+ my $return=&exists($user, $domain, $newfilename);
+ $request->print($return);
+ if ($return =~/^Error:/) {
+ $request->print('
Cancel');
+ return;
+ }
+ $request->print('
Copy '.&display($fn).'
to '.
+ &display($newfilename).'?
No such file: '.&display($fn).'
'); } - $request->print('Copy '.&display($fn).'
to '.
- &display($newfilename).'?
No such file: '.&display($fn).'
'); - } } =pod