--- loncom/publisher/loncfile.pm 2005/05/25 22:27:17 1.68 +++ loncom/publisher/loncfile.pm 2005/07/14 22:49:26 1.70 @@ -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.70 2005/07/14 22:49:26 raeburn 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 @@ -519,11 +544,20 @@ sub Delete1 { if( -e $fn) { $request->print(''); - unless (&obsolete_unpub($user,$domain,$fn)) { - $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').'