[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 09 Jan 2003 22:11:52 -0000


albertel		Thu Jan  9 17:11:52 2003 EDT

  Modified files:              
    /loncom/publisher	loncfile.pm 
  Log:
  - Fixes condition where one could copy a file to a directory. BUG#1142
  - Must suply filename in all cases
  
  
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.20 loncom/publisher/loncfile.pm:1.21
--- loncom/publisher/loncfile.pm:1.20	Wed Nov 27 12:05:50 2002
+++ loncom/publisher/loncfile.pm	Thu Jan  9 17:11:52 2003
@@ -10,7 +10,7 @@
 # 
 
 #
-# $Id: loncfile.pm,v 1.20 2002/11/27 17:05:50 albertel Exp $
+# $Id: loncfile.pm,v 1.21 2003/01/09 22:11:52 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -323,20 +323,24 @@
   my ($user, $domain, $dir, $file) = @_;
 
   # Create complete paths in publication and construction space.
-
-  my $published = &PublicationPath($domain, $user, $dir, $file);
-  my $construct = &ConstructionPath($user, $dir, $file);
+  my $relativedir=$dir;
+  $relativedir=s|/home/\Q$user\E/public_html||;
+  my $published = &PublicationPath($domain, $user, $relativedir, $file);
+  my $construct = &ConstructionPath($user, $relativedir, $file);
 
   # If the resource exists in either space indicate this fact.
   # Note that the check for existence in resource space is stricter.
 
   my $result;    
+  if ( -d $construct ) {
+      return 'Error: destination for operation is a directory.';
+  }
   if ( -e $published) {
-    $result.='<p><font color=red>Warning: target file exists, and has been published!</font></p>';
+      $result.='<p><font color=red>Warning: target file exists, and has been published!</font></p>';
   }
   elsif ( -e $construct) {
-    $result.='<p><font color=red>Warning: target file exists!</font></p>';
-   }
+      $result.='<p><font color=red>Warning: target file exists!</font></p>';
+  }
 
   return $result;
 
@@ -492,7 +496,12 @@
 	if($ENV{'form.newfilename'}) {
 	    my $newfilename = $ENV{'form.newfilename'};
 	    $request->print(&checksuffix($filename, $newfilename));
-	    $request->print(&exists($user, $domain, $dir, $newfilename));
+	    my $return=&exists($user, $domain, $dir, $newfilename);
+	    $request->print($return);
+	    if ($return =~/^Error:/) {
+		$request->print('<br /><a href="'.$cancelurl.'">Cancel</a>');
+		return;
+	    }
 	    my $dest=&SimplifyDir($dir,$newfilename);
 	    $request->print('<input type=hidden name=newfilename value="'.
 			    $newfilename.
@@ -590,7 +599,12 @@
 
   if(-e $filename) {
     $request->print(&checksuffix($filename,$newfilename));
-    $request->print(&exists($user, $domain, $dir, $newfilename));
+    my $return=&exists($user, $domain, $dir, $newfilename);
+    $request->print($return);
+    if ($return =~/^Error:/) {
+	$request->print('<br /><a href="'.$cancelurl.'">Cancel</a>');
+	return;
+    }
     my $dest=&SimplifyDir($dir,$newfilename);
     $request->print('<input type = hidden name = newfilename value = "'.
 		    $dir.'/'.$newfilename.