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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 11 Sep 2003 21:02:38 -0000


albertel		Thu Sep 11 17:02:38 2003 EDT

  Modified files:              
    /loncom/publisher	loncfile.pm publisher.html 
  Log:
  - fixes BUG#2133
     - adds a 'Move file' that is an alias for Rename
     -for copy and rename if the sourec is a file and the dest is a directory the file is copied/renamed to the new directory with the same previous name
     - copy preserves previous file extension if none was specified
  
  
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.41 loncom/publisher/loncfile.pm:1.42
--- loncom/publisher/loncfile.pm:1.41	Thu Aug 28 16:28:33 2003
+++ loncom/publisher/loncfile.pm	Thu Sep 11 17:02:38 2003
@@ -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 @@
 
     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 @@
 	    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 @@
 =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('<br /><a href="'.&url($fn).'">Cancel</a>');
-	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('<br /><a href="'.&url($fn).'">Cancel</a>');
+	    return;
+	}
+	$request->print('<input type="hidden" name="newfilename" value="'.
+			$newfilename.
+			'" /><p>Copy '.&display($fn).'<br />to '.
+			&display($newfilename).'?</p>');
+	&CloseForm1($request, $fn);
+    } else {
+	$request->print('<p>No such file: '.&display($fn).'</p></form>');
     }
-    $request->print('<input type = "hidden" name = "newfilename" value = "'.
-		    $newfilename.
-		    '" /><p>Copy '.&display($fn).'<br />to '.
-		    &display($newfilename).'?</p>');
-    &CloseForm1($request, $fn);
-  } else {
-    $request->print('<p>No such file: '.&display($fn).'</p></form>');
-  }
 }
 
 =pod
Index: loncom/publisher/publisher.html
diff -u loncom/publisher/publisher.html:1.32 loncom/publisher/publisher.html:1.33
--- loncom/publisher/publisher.html:1.32	Thu Sep  4 22:22:25 2003
+++ loncom/publisher/publisher.html	Thu Sep 11 17:02:38 2003
@@ -150,6 +150,7 @@
                             <option value="newstyfile">New style file:</option>
 			    <option value="newdir">New subdirectory:</option>
 			    <option value="rename">Rename current file to:</option>
+			    <option value="rename">Move current file to:</option>
 			    <option value="copy">Copy current file to:</option>
 			  </select>&nbsp;<input type="text" name="newfilename" value="Type Name Here" onFocus="if (this.value == 'Type Name Here') this.value=''" />&nbsp;<input type="button" value="Go" onClick="getactionfilename();" />
 		      </nobr>