--- loncom/publisher/loncfile.pm 2005/08/16 15:52:08 1.71
+++ loncom/publisher/loncfile.pm 2008/09/24 17:30:18 1.90
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.71 2005/08/16 15:52:08 raeburn Exp $
+# $Id: loncfile.pm,v 1.90 2008/09/24 17:30:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -69,10 +69,11 @@ use File::Copy;
use HTML::Entities();
use Apache::Constants qw(:common :http :methods);
use Apache::loncacc;
-use Apache::Log ();
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonlocal;
+use LONCAPA qw(:DEFAULT :match);
+
my $DEBUG=0;
my $r; # Needs to be global for some stuff RF.
@@ -101,20 +102,24 @@ my $r; # Needs to be global for some
=cut
sub Debug {
-
- # Marshall the parameters.
-
- my $r = shift;
- my $log = $r->log;
- my $message = shift;
-
# Put out the indicated message butonly if DEBUG is true.
-
if ($DEBUG) {
+ my ($r,$message) = @_;
$r->log_reason($message);
}
}
+sub done {
+ my ($url)=@_;
+ my $done=&mt("Done");
+ return(<$done
+
+ENDDONE
+}
+
=pod
=item URLToPath($url)
@@ -156,22 +161,22 @@ sub URLToPath {
$Url=~ s/\/+/\//g;
$Url=~ s/^http\:\/\/[^\/]+//;
$Url=~ s/^\///;
- $Url=~ s/(\~|priv\/)(\w+)\//\/home\/$2\/public_html\//;
+ $Url=~ s/(\~|priv\/)($match_username)\//\/home\/$2\/public_html\//;
&Debug($r, "Returning $Url \n");
return $Url;
}
sub url {
my $fn=shift;
- $fn=~s/^\/home\/(\w+)\/public\_html/\/priv\/$1/;
+ $fn=~s/^\/home\/($match_username)\/public\_html/\/priv\/$1/;
$fn=&HTML::Entities::encode($fn,'<>"&');
return $fn;
}
sub display {
my $fn=shift;
- $fn=~s-^/home/(\w+)/public_html-/priv/$1-;
- return ''.$fn.'';
+ $fn=~s-^/home/($match_username)/public_html-/priv/$1-;
+ return ''.$fn.'';
}
@@ -195,20 +200,20 @@ sub obsolete_unpub {
}
# see if directory is empty
-# ignores any .meta, .save and .log files created for a previously
+# ignores any .meta, .save, .bak, and .log files created for a previously
# published file, which has since been marked obsolete and deleted.
sub empty_directory {
my ($dirname,$phase) = @_;
if (opendir DIR, $dirname) {
my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and ..
if (@files) {
- my @orphans = grep(/\.(meta|save|log)$/,@files);
+ my @orphans = grep(/\.(meta|save|log|bak)$/,@files);
if (scalar(@files) - scalar(@orphans) > 0) {
return 0;
} else {
if (($phase eq 'Delete2') && (@orphans > 0)) {
foreach my $file (@orphans) {
- if ($file =~ /\.(meta|save|log)$/) {
+ if ($file =~ /\.(meta|save|log|bak)$/) {
unlink($dirname.$file);
}
}
@@ -232,12 +237,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
@@ -245,6 +254,9 @@ Returns:
=over 4
+=item string - Either undef, 'warning' or 'error' depending on the
+ type of problem
+
=item string - Either where the resource exists as an html string that can
be embedded in a dialog or an empty string if the resource
does not exist.
@@ -254,20 +266,39 @@ 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\//;
- my $result='';
+ s{^/home/$user/public_html/}{/home/httpd/html/res/$domain/$user/};
+ my ($type,$result);
if ( -d $construct ) {
- return &mt('Error: destination for operation is an existing directory.');
+ return ('error','
'.&mt('Error: destination for operation is an existing directory.').'
');
+
}
+
if ( -e $published) {
- $result.='
'.&mt('Warning: target file exists, and has been published!').'
';
}
- return $result;
+
+ return ($type,$result);
}
=pod
@@ -306,9 +337,9 @@ sub checksuffix {
my $newsuffix;
if ($new=~m:(.*/*)([^/]+)\.(\w+)$:) { $newsuffix=$3; }
if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; }
- if ($oldsuffix ne $newsuffix) {
+ if (lc($oldsuffix) ne lc($newsuffix)) {
$result.=
- '
'.&mt('Warning: change of MIME type!').'
';
+ '
'.&mt('Warning: change of MIME type!').'
';
}
return $result;
}
@@ -321,20 +352,27 @@ sub cleanDest {
$foundbad=1;
$dest=~s/\.//g;
}
- if ($dest=~/[\#\?&%\"]/) {
+ $dest =~ s/(\s+$|^\s+)//g;
+ if ($dest=~/[\#\?&%\":]/) {
$foundbad=1;
- $dest=~s/[\#\?&%\"]//g;
+ $dest=~s/[\#\?&%\":]//g;
}
if ($dest=~m|/|) {
my ($newpath)=($dest=~m|(.*)/|);
$newpath=&relativeDest($fn,$newpath,$uname);
if (! -d "$newpath") {
- $request->print("
".&mt('You have requested to create file in directory [_1] which doesn\'t exist. The requested directory path has been removed from the requested file name.','"'.$newpath.'"')."
");
+ $request->print("
".&mt('You have requested to create file in directory [_1] which doesn\'t exist. The requested directory path has been removed from the requested file name.','"'.&display($newpath).'"')."
");
$dest=~s|.*/||;
}
}
+ if ($dest =~ /\.(\d+)\.(\w+)$/){
+ $request->print(''
+ .&mt('Bad filename [_1]. (name).(number).(extension) not allowed. Removing the .number. from requested filename.',&display($dest))
+ .'');
+ $dest =~ s/\.(\d+)(\.\w+)$/$2/;
+ }
if ($foundbad) {
- $request->print("
".&mt('Invalid characters in requested name have been removed.')."
");
+ $request->print("
".&mt('Invalid characters in requested name have been removed.')."