[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm
taceyjo1
lon-capa-cvs@mail.lon-capa.org
Sat, 13 Dec 2003 19:54:16 -0000
taceyjo1 Sat Dec 13 14:54:16 2003 EDT
Modified files:
/loncom/publisher loncfile.pm
Log:
Deleting of directoies is now included, also fixed a regular expression mistake that allows for more graceful handling of files that do not have extensions, let me know if it breaks anything
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.45 loncom/publisher/loncfile.pm:1.46
--- loncom/publisher/loncfile.pm:1.45 Wed Nov 19 10:06:33 2003
+++ loncom/publisher/loncfile.pm Sat Dec 13 14:54:16 2003
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.45 2003/11/19 15:06:33 taceyjo1 Exp $
+# $Id: loncfile.pm,v 1.46 2003/12/13 19:54:16 taceyjo1 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -110,7 +110,7 @@
# Put out the indicated message butonly if DEBUG is true.
if ($DEBUG) {
- $log->debug($message);
+ $r->log_reason($message);
}
}
@@ -851,16 +851,40 @@
sub Delete2 {
my ($request, $user, $filename) = @_;
-
- if(-e $filename) {
- unless(unlink($filename)) {
- $request->print('<font color="red">Error: '.$!.'</font>');
+ if(opendir DIR, $filename) {
+ my @files=readdir(DIR);
+ shift @files; shift @files; # takes off . and ..
+ if(@files) {
+ $request->print('<font color="red"> Error: Directory Non Empty</font>');
return 0;
}
- } else {
- $request->print('<p> No such file. </p></form');
- return 0;
+ else {
+ if(-e $filename) {
+ unless(rmdir($filename)) {
+ $request->print('<font color="red">Error: '.$!.'</font>');
+ return 0;
+ }
+ }
+ else {
+ $request->print('<p> No such file. </p></form');
+ return 0;
+ }
+
+ }
+
+ }
+ else {
+ if(-e $filename) {
+ unless(unlink($filename)) {
+ $request->print('<font color="red">Error: '.$!.'</font>');
+ return 0;
+ }
+ }
+ else {
+ $request->print('<p> No such file. </p></form');
+ return 0;
}
+ }
return 1;
}
@@ -999,13 +1023,14 @@
my $dir; # Directory path
my $main; # Filename.
my $suffix; # Extension.
-
- if ($fn=~m:(.*)/([^/]+)\.(\w+)$:) {
+ if ($fn=~m:(.*)/([^/]+):) {
$dir=$1; # Directory path
$main=$2; # Filename.
- $suffix=$3; # Extension.
- }
-
+ }
+ if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions
+ $main=$`;
+ $suffix=$1;
+ }
my $dest; # On success this is where we'll go.
&Debug($r,