--- loncom/publisher/loncfile.pm 2007/04/26 21:17:16 1.83 +++ loncom/publisher/loncfile.pm 2007/07/23 23:53:31 1.85 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.83 2007/04/26 21:17:16 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 @@ sub empty_directory { =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 @@ Returns: =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 @@ sub exists { $type = 'warning'; $result.='

'.&mt('Warning: target file exists, and has been published!').'

'; } else { - $type = 'warning'; - $result.='

'.&mt('Warning: a published file of this names exists.').'

'; + my $published_type = (-d $published) ? 'directory' : 'file'; + + if ($published_type eq $creating) { + $type = 'warning'; + $result.='

'.&mt("Warning: a published $published_type of this name exists.").'

'; + } else { + $type = 'error'; + $result.='

'.&mt("Error: a published $published_type of this name exists.").'

'; + } } } elsif ( -e $construct) { $type = 'warning'; @@ -340,6 +353,12 @@ sub cleanDest { $dest=~s|.*/||; } } + if ($dest =~ /\.(\d+)\.(\w+)$/){ + $request->print('' + .&mt('Bad filename [_1].
(name).(number).(extension) not allowed.
Removing the .number. from requested filename.',$dest) + .'
'); + $dest =~ s/\.(\d+)(\.\w+)$/$2/; + } if ($foundbad) { $request->print("

".&mt('Invalid characters in requested name have been removed.')."

"); } @@ -674,9 +693,9 @@ causes the newdir operation to transitio 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(''); } else { if ($mode eq 'testbank') {