--- loncom/publisher/loncfile.pm 2009/12/02 09:53:02 1.103
+++ loncom/publisher/loncfile.pm 2016/05/22 01:09:54 1.124
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.103 2009/12/02 09:53:02 bisitz Exp $
+# $Id: loncfile.pm,v 1.124 2016/05/22 01:09:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,7 +37,7 @@
=head1 NAME
-Apache::loncfile - Construction space file management.
+Apache::loncfile - Authoring space file management.
=head1 SYNOPSIS
@@ -68,7 +68,6 @@ use File::Basename;
use File::Copy;
use HTML::Entities();
use Apache::Constants qw(:common :http :methods);
-use Apache::loncacc;
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonlocal;
@@ -102,7 +101,7 @@ my $r; # Needs to be global for some
=cut
sub Debug {
- # Put out the indicated message butonly if DEBUG is true.
+ # Put out the indicated message but only if DEBUG is true.
if ($DEBUG) {
my ($r,$message) = @_;
$r->log_reason($message);
@@ -110,14 +109,15 @@ sub Debug {
}
sub done {
- my ($url)=@_;
- my $done=&mt("Done");
- return(<$done
-
-ENDDONE
+ my ($url) = @_;
+ return
+ '
';
}
=pod
@@ -158,24 +158,28 @@ Global References
sub URLToPath {
my $Url = shift;
&Debug($r, "UrlToPath got: $Url");
- $Url=~ s/\/+/\//g;
- $Url=~ s/^https?\:\/\/[^\/]+//;
- $Url=~ s/^\///;
- $Url=~ s/(\~|priv\/)($match_username)\//\/home\/$2\/public_html\//;
+ $Url=~ s{^https?\://[^/]+}{};
+ $Url=~ s{//+}{/}g;
+ $Url=~ s{^/}{};
+ $Url=$Apache::lonnet::perlvar{'lonDocRoot'}."/$Url";
&Debug($r, "Returning $Url \n");
return $Url;
}
sub url {
my $fn=shift;
- $fn=~s/^\/home\/($match_username)\/public\_html/\/priv\/$1/;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ $fn=~ s/^\Q$londocroot\E//;
+ $fn=~s{/\./}{/}g;
$fn=&HTML::Entities::encode($fn,'<>"&');
return $fn;
}
sub display {
my $fn=shift;
- $fn=~s-^/home/($match_username)/public_html-/priv/$1-;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ $fn=~s/^\Q$londocroot\E//;
+ $fn=~s{/\./}{/}g;
return ''.$fn.'';
}
@@ -186,9 +190,9 @@ sub display {
sub obsolete_unpub {
my ($user,$domain,$construct)=@_;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
my $published=$construct;
- $published=~
- s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//;
+ $published=~s{^\Q$londocroot/priv/\E}{$londocroot/res/};
if (-e $published) {
if (&Apache::lonnet::metadata($published,'obsolete')) {
return 1;
@@ -202,12 +206,13 @@ sub obsolete_unpub {
# see if directory is empty
# ignores any .meta, .save, .bak, and .log files created for a previously
# published file, which has since been marked obsolete and deleted.
+# ignores a .DS_Store file put there when viewing directory via webDAV on MacOS.
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|bak)$/,@files);
+ my @orphans = grep(/\.(meta|save|log|bak|DS_Store)$/,@files);
if (scalar(@files) - scalar(@orphans) > 0) {
return 0;
} else {
@@ -230,7 +235,7 @@ sub empty_directory {
=item exists($user, $domain, $file)
- Determine if a resource file name has been published or exists
+ Determine if a resource filename has been published or exists
in the construction space.
Parameters:
@@ -269,33 +274,33 @@ sub exists {
my ($user, $domain, $construct, $creating) = @_;
$creating ||= 'file';
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
my $published=$construct;
- $published=~
- s{^/home/$user/public_html/}{/home/httpd/html/res/$domain/$user/};
+ $published=~s{^\Q$londocroot/priv/\E}{$londocroot/res/};
my ($type,$result);
if ( -d $construct ) {
- return ('error','
'.&mt('Error: destination for operation is an existing directory.').'
');
+ return ('error','
'.&mt('Error: destination for operation is an existing directory.').'
');
}
if ( -e $published) {
if ( -e $construct ) {
$type = 'warning';
- $result.='
'.&mt('Warning: target file exists, and has been published!').'
';
+ $result.='
'.&mt('Warning: target file exists, and has been published!').'
';
}
return ($type,$result);
@@ -339,15 +344,16 @@ sub checksuffix {
if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; }
if (lc($oldsuffix) ne lc($newsuffix)) {
$result.=
- '
'.&mt('Warning: change of MIME type!').'
';
+ '
'.&mt('Warning: change of MIME type!').'>
';
}
return $result;
}
sub cleanDest {
- my ($request,$dest,$subdir,$fn,$uname)=@_;
+ my ($request,$dest,$subdir,$fn,$uname,$udom)=@_;
#remove bad characters
my $foundbad=0;
+ my $error='';
if ($subdir && $dest =~/\./) {
$foundbad=1;
$dest=~s/\.//g;
@@ -359,49 +365,56 @@ sub cleanDest {
}
if ($dest=~m|/|) {
my ($newpath)=($dest=~m|(.*)/|);
- $newpath=&relativeDest($fn,$newpath,$uname);
+ ($newpath,$error)=&relativeDest($fn,$newpath,$uname,$udom);
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."
+ $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 filename."
,&display($newpath))
- .'
');
+ .'
');
$dest=~s|.*/||;
}
}
if ($dest =~ /\.(\d+)\.(\w+)$/){
- $request->print('
'
+ $request->print('
'
.&mt('Bad filename [_1]',&display($dest))
.' '
.&mt('[_1](name).(number).(extension)[_2] not allowed.','','')
.' '
.&mt('Removing the [_1].number.[_2] from requested filename.','','')
- .'