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

www lon-capa-cvs@mail.lon-capa.org
Tue, 26 Aug 2003 19:17:02 -0000


www		Tue Aug 26 15:17:02 2003 EDT

  Modified files:              
    /loncom/publisher	loncfile.pm 
  Log:
  Bug #2004: when renaming a file, also rename hidden files.
  Jay Ihry
  
  
  
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.39 loncom/publisher/loncfile.pm:1.40
--- loncom/publisher/loncfile.pm:1.39	Mon Aug  4 16:34:19 2003
+++ loncom/publisher/loncfile.pm	Tue Aug 26 15:17:02 2003
@@ -9,7 +9,7 @@
 #  and displays a page showing the results of the action.
 #
 #
-# $Id: loncfile.pm,v 1.39 2003/08/04 20:34:19 www Exp $
+# $Id: loncfile.pm,v 1.40 2003/08/26 19:17:02 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -605,6 +605,14 @@
 
     if ($ENV{'form.action'} =~ /new(.+)file/) {
 	my $extension=$1;
+
+        ##Informs User (name).(number).(extension) not allowed 
+	if($newfilename =~ /\.(\d+)\.(\w+)$/){
+	    $r->print('<font color="red">'.$newfilename.
+		      ' - Bad Filename<br />(name).(number).(extension)'.
+		      ' Not Allowed</font>');
+	    return;
+	}
 	if ($newfilename !~ /\Q.$extension\E$/) {
 	    if ($newfilename =~ m|^[^\.]*\.([^\.]+)$|) {
 		#already has an extension strip it and add in expected one
@@ -736,9 +744,43 @@
   &Debug($request, "Target is: ".$directory.'/'.
 	 $newfile);
   if (-e $oldfile) {
+
+      my $oRN=$oldfile;
+      my $nRN=$newfile;
       unless (rename($oldfile,$newfile)) {
 	  $request->print('<font color="red">Error: '.$!.'</font>');
 	  return 0;
+      }
+      ## If old name.(extension) exits, move under new name.
+      ## If it doesn't exist and a new.(extension) exists  
+      ## delete it (only concern when renaming over files)
+      my $tmp1=$oRN.'.meta';
+      my $tmp2=$nRN.'.meta';
+      if(-e $tmp1){
+	  unless(rename($tmp1,$tmp2)){ }
+      }else if(-e $tmp2){
+	  unlink $tmp2;
+      }
+      $tmp1=$oRN.'.save';
+      $tmp2=$nRN.'.save';
+      if(-e $tmp1){
+	  unless(rename($tmp1,$tmp2)){ }
+      }else if(-e $tmp2){
+	  unlink $tmp2;
+      }
+      $tmp1=$oRN.'.log';
+      $tmp2=$nRN.'.log';
+      if(-e $tmp1){
+	  unless(rename($tmp1,$tmp2)){ }
+      }else if(-e $tmp2){
+	  unlink $tmp2;
+      }
+      $tmp1=$oRN.'.bak';
+      $tmp2=$nRN.'.bak';
+      if(-e $tmp1){
+	  unless(rename($tmp1,$tmp2)){ }
+      }else if(-e $tmp2){
+	  unlink $tmp2;
       }
   } else {
       $request->print("<p> No such file: ".&display($oldfile).'</p></form>');