--- loncom/publisher/loncfile.pm 2005/05/25 22:27:17 1.68
+++ loncom/publisher/loncfile.pm 2006/11/22 22:10:58 1.78
@@ -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.78 2006/11/22 22:10:58 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -69,10 +69,12 @@ 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 lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
my $DEBUG=0;
my $r; # Needs to be global for some stuff RF.
@@ -101,16 +103,9 @@ 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);
}
}
@@ -194,7 +189,32 @@ 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.
+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);
+ if (scalar(@files) - scalar(@orphans) > 0) {
+ return 0;
+ } else {
+ if (($phase eq 'Delete2') && (@orphans > 0)) {
+ foreach my $file (@orphans) {
+ if ($file =~ /\.(meta|save|log|bak)$/) {
+ unlink($dirname.$file);
+ }
+ }
+ }
+ }
+ }
+ closedir(DIR);
+ return 1;
+ }
+ return 0;
+}
=pod
@@ -296,9 +316,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 +539,20 @@ sub Delete1 {
if( -e $fn) {
$request->print('');
- unless (&obsolete_unpub($user,$domain,$fn)) {
- $request->print('
'.&mt('Cannot delete non-obsolete published file').'