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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Mon, 23 Jul 2007 23:53:32 -0000


albertel		Mon Jul 23 19:53:32 2007 EDT

  Modified files:              
    /loncom/publisher	loncfile.pm 
  Log:
  - bug#1860, allow case where trying to recreate a directory of the same name of a previously created directory that has had items published out of it before.
  - prevent user form creating a file that is the same name as a directory that has been created and published out of before
  
  
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.84 loncom/publisher/loncfile.pm:1.85
--- loncom/publisher/loncfile.pm:1.84	Tue Jul 10 19:34:54 2007
+++ loncom/publisher/loncfile.pm	Mon Jul 23 19:53:31 2007
@@ -9,7 +9,7 @@
 #  and displays a page showing the results of the action.
 #
 #
-# $Id: loncfile.pm,v 1.84 2007/07/10 23:34:54 albertel Exp $
+# $Id: loncfile.pm,v 1.85 2007/07/23 23:53:31 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -226,12 +226,16 @@
 
 =over 4
 
-=item  $user   - string [in] - Name of the user for which to check.
+=item  $user     - string [in] - Name of the user for which to check.
 
-=item  $domain - string [in] - Name of the domain in which the resource
+=item  $domain   - string [in] - Name of the domain in which the resource
                           might have been published.
 
-=item  $file   - string [in] - Name of the file.
+=item  $file     - string [in] - Name of the file.
+
+=item  $creating - string [in] - optional, type of object being created,
+                               either 'directory' or 'file'. Defaults to
+                               'file' if unspecified.
 
 =back
 
@@ -251,7 +255,9 @@
 =cut
 
 sub exists {
-    my ($user, $domain, $construct) = @_;
+    my ($user, $domain, $construct, $creating) = @_;
+    $creating ||= 'file';
+
     my $published=$construct;
     $published=~
 	s{^/home/$user/public_html/}{/home/httpd/html/res/$domain/$user/};
@@ -266,8 +272,15 @@
 	    $type = 'warning';
 	    $result.='<p><span class="LC_warning">'.&mt('Warning: target file exists, and has been published!').'</span></p>';
 	} else {
-	    $type = 'warning';
-	    $result.='<p><span class="LC_warning">'.&mt('Warning: a published file of this names exists.').'</span></p>';
+	    my $published_type = (-d $published) ? 'directory' : 'file';
+
+	    if ($published_type eq $creating) {
+		$type = 'warning';
+		$result.='<p><span class="LC_warning">'.&mt("Warning: a published $published_type of this name exists.").'</span></p>';
+	    } else {
+		$type = 'error';
+		$result.='<p><span class="LC_error">'.&mt("Error: a published $published_type of this name exists.").'</span></p>';
+	    }
 	}
     } elsif ( -e $construct) {
 	$type = 'warning';
@@ -680,9 +693,9 @@
 sub NewDir1 {
     my ($request, $username, $domain, $fn, $newfilename, $mode) = @_;
 
-    my ($type, $result)=&exists($username,$domain,$newfilename);
+    my ($type, $result)=&exists($username,$domain,$newfilename,'directory');
     $request->print($result);
-    if ($result) {
+    if ($type eq 'error') {
 	$request->print('</form>');
     } else {
 	if ($mode eq 'testbank') {