--- loncom/publisher/loncfile.pm 2005/05/25 22:27:17 1.68
+++ loncom/publisher/loncfile.pm 2005/08/26 19:44:16 1.72
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.68 2005/05/25 22:27:17 albertel Exp $
+# $Id: loncfile.pm,v 1.72 2005/08/26 19:44:16 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -194,7 +194,32 @@ sub obsolete_unpub {
}
}
-
+# see if directory is empty
+# ignores any .meta, .save 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);
+ if (scalar(@files) - scalar(@orphans) > 0) {
+ return 0;
+ } else {
+ if (($phase eq 'Delete2') && (@orphans > 0)) {
+ foreach my $file (@orphans) {
+ if ($file =~ /\.(meta|save|log)$/) {
+ unlink($dirname.$file);
+ }
+ }
+ }
+ }
+ }
+ closedir(DIR);
+ return 1;
+ }
+ return 0;
+}
=pod
@@ -296,9 +321,9 @@ sub cleanDest {
$foundbad=1;
$dest=~s/\.//g;
}
- if ($dest=~/[\#\?&%\"]/) {
+ if ($dest=~/[\#\?&%\":]/) {
$foundbad=1;
- $dest=~s/[\#\?&%\"]//g;
+ $dest=~s/[\#\?&%\":]//g;
}
if ($dest=~m|/|) {
my ($newpath)=($dest=~m|(.*)/|);
@@ -519,11 +544,20 @@ sub Delete1 {
if( -e $fn) {
$request->print('');
- unless (&obsolete_unpub($user,$domain,$fn)) {
- $request->print('
'.&mt('Cannot delete non-obsolete published file').'
'.
+ if (-d $fn) {
+ unless (&empty_directory($fn,'Delete1')) {
+ $request->print(''.&mt('Only empty directories may be deleted.').'
'.
+ 'You must delete the contents of the directory first.
'.
+ '
'.&mt('Cancel').'');
+ return;
+ }
+ } else {
+ unless (&obsolete_unpub($user,$domain,$fn)) {
+ $request->print(''.&mt('Cannot delete non-obsolete published file').'
'.
'
'.&mt('Cancel').'');
- return;
- }
+ return;
+ }
+ }
$request->print(''.&mt('Delete').' '.&display($fn).'?
');
&CloseForm1($request, $fn);
} else {
@@ -710,7 +744,13 @@ sub NewFile1 {
##Informs User (name).(number).(extension) not allowed
if($newfilename =~ /\.(\d+)\.(\w+)$/){
$r->print(''.$newfilename.
- ' - '.&mt('Bad Filename').'
('.&mt('name').').('.&mt('number').').('.&mt('extension').')'.
+ ' - '.&mt('Bad Filename').'
('.&mt('name').').('.&mt('number').').('.&mt('extension').') '.
+ ' '.&mt('Not Allowed').'');
+ return;
+ }
+ if($newfilename =~ /(\:\:\:|\&\&\&|\_\_\_)/){
+ $r->print(''.$newfilename.
+ ' - '.&mt('Bad Filename').'
('.&mt('Must not include').' '.$1.') '.
' '.&mt('Not Allowed').'');
return;
}
@@ -932,10 +972,8 @@ Returns:
sub Delete2 {
my ($request, $user, $filename) = @_;
- if(opendir DIR, $filename) {
- my @files=readdir(DIR);
- shift @files; shift @files; # takes off . and ..
- if(@files) {
+ if (-d $filename) {
+ unless (&empty_directory($filename,'Delete2')) {
$request->print(' '.&mt('Error: Directory Non Empty').'');
return 0;
} else {
@@ -987,7 +1025,7 @@ sub Delete2 {
=back
-Returns 0 failure, and 0 successs.
+Returns 0 failure, and 1 successs.
=cut
@@ -995,6 +1033,10 @@ sub Copy2 {
my ($request, $username, $dir, $oldfile, $newfile) = @_;
&Debug($request ,"Will try to copy $oldfile to $newfile");
if(-e $oldfile) {
+ if ($oldfile eq $newfile) {
+ $request->print(' '.&mt('Warning').': '.&mt('Name of new file is the same as name of old file').' - '.&mt('no action taken').'.');
+ return 1;
+ }
unless (copy($oldfile, $newfile)) {
$request->print(' '.&mt('copy Error').': '.$!.'');
return 0;