[LON-CAPA-cvs] cvs: loncom /build Makefile /debugging_tools clean_db.pl doc/loncapafiles buildfiles.lpml clean_file_permissions.piml

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 18 Mar 2005 20:07:21 -0000


albertel		Fri Mar 18 15:07:21 2005 EDT

  Added files:                 
    /loncom/debugging_tools	clean_db.pl 
    /doc/loncapafiles	clean_file_permissions.piml 

  Modified files:              
    /doc/loncapafiles	buildfiles.lpml 
    /loncom/build	Makefile 
  Log:
  - cleaning file_permisions on install
  
  
Index: doc/loncapafiles/buildfiles.lpml
diff -u doc/loncapafiles/buildfiles.lpml:1.14 doc/loncapafiles/buildfiles.lpml:1.15
--- doc/loncapafiles/buildfiles.lpml:1.14	Thu Aug 12 14:42:34 2004
+++ doc/loncapafiles/buildfiles.lpml	Fri Mar 18 15:07:21 2005
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- buildfiles.lpml -->
 
-<!-- $Id: buildfiles.lpml,v 1.14 2004/08/12 18:42:34 albertel Exp $ -->
+<!-- $Id: buildfiles.lpml,v 1.15 2005/03/18 20:07:21 albertel Exp $ -->
 
 <!--
 
@@ -151,6 +151,16 @@
 </note>
 </file>
 <file>
+  <source>doc/loncapafiles/clean_file_permissions.piml</source>
+  <target dist='default'>clean_file_permissions.piml</target>
+  <categoryname>system file</categoryname>
+  <description>
+Executes clean_db.pl on each file_permisions.db file to remove erroneuos keys.
+  </description>
+  <note>
+  </note>
+</file>
+<file>
 <source>doc/loncapafiles/accesscount_seed.piml</source>
 <target dist='default'>accesscount_seed.piml</target>
 <categoryname>system file</categoryname>
Index: loncom/build/Makefile
diff -u loncom/build/Makefile:1.172 loncom/build/Makefile:1.173
--- loncom/build/Makefile:1.172	Thu Dec 16 15:14:37 2004
+++ loncom/build/Makefile	Fri Mar 18 15:07:21 2005
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 
-# $Id: Makefile,v 1.172 2004/12/16 20:14:37 matthew Exp $
+# $Id: Makefile,v 1.173 2005/03/18 20:07:21 albertel Exp $
 
 # TYPICAL USAGE of this Makefile is primarily for two targets:
 # "make build" and "make install".
@@ -119,6 +119,8 @@
 	@echo "         system"
 	@echo "sanitycheck: probe for common errors and recommend fixes to"
 	@echo "             the user"
+	@echo "clean_file_permissions: Remove erroneous keys from the  "
+	@echo "    file_permissions.db"
 	@echo "accesscount_seed: Migrate the access counting mechanism from "
 	@echo "    nohist_reseval.db to nohist_accesscount.db."
 	@echo "modify_config_files: Perform automatic update of the "
@@ -430,6 +432,11 @@
 	cat $(SOURCE)/doc/loncapafiles/run_searchcat.piml | \
 	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(QUERYLAUNCH)
 
+clean_file_permissions:
+	cat $(SOURCE)/doc/loncapafiles/clean_file_permissions.piml | \
+	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
+	tee -a WARNINGS
+
 accesscount_seed:
 	cat $(SOURCE)/doc/loncapafiles/accesscount_seed.piml | \
 	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
@@ -463,6 +470,7 @@
 postinstall:
 	make webserverconf
 	make reseval_fixup
+	make clean_file_permissions
 	make accesscount_seed
 	make modify_config_files
 	make clearoutoldspreadsheetcache

Index: loncom/debugging_tools/clean_db.pl
+++ loncom/debugging_tools/clean_db.pl
#!/usr/bin/perl -w
#
# The LearningOnline Network
#
# dump_db.pl - dump a GDBM database to standard output, unescaping if asked to.
#
# $Id: clean_db.pl,v 1.1 2005/03/18 20:07:21 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
#################################################
use strict;
use Getopt::Long;
use GDBM_File;

#
# Options
my ($unesc,$help,$localize_times) = (0,0,0);
GetOptions(     "help"     => \$help);

#
# Help them out if they ask for it
if ($help) {
    print <<END;
clean_db.pl - clean a db of a certain key
Specify the database filename on the command line.
And the Key to remove.
Options:
   --help     Display this help.
   --unescape Unescape the keys and values before printing them out.
   -u        Same as --unescape
   -t        Localize times when possible (human readable times)
Example: 
    dump_db.pl mydata.db "error:"
END
    exit;
}

my $fname = shift;
my $key_to_remove = shift;

my %db;
if (! tie(%db,'GDBM_File',$fname,&GDBM_WRITER,0640)) {
    warn "Unable to tie to $fname";
    exit;
}
while (my ($key,$value) = each(%db)) {
    if ($key ne $key_to_remove) { next; }
    delete($db{$key});
    if ($fname =~ m|/nohist_[^/]*.db|) { exit; }
    my $hist=$fname;
    $hist=~s/\.db$/.hist/;
    open(HIST,">>$hist");
    print HIST "D:".time.":$key\n";
    close(HIST);
}
exit;


Index: doc/loncapafiles/clean_file_permissions.piml
+++ doc/loncapafiles/clean_file_permissions.piml
<!DOCTYPE piml PUBLIC "-//TUX/DTD piml 1.0 Final//EN" 
	"http://lpml.sourceforge.net/DTD/piml.dtd">
<!-- accesscount_seed.piml -->
<!-- Matthew Hall -->

<!-- $Id: clean_file_permissions.piml,v 1.1 2005/03/18 20:07:21 albertel Exp $ -->

<!--

This file is part of the LearningOnline Network with CAPA (LON-CAPA).

LON-CAPA is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

LON-CAPA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with LON-CAPA; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

/home/httpd/html/adm/gpl.txt

http://www.lon-capa.org/

-->

<piml>
<targetroot>/</targetroot>
<files>
<file>
<target dist="default">/home/httpd/lonUsers</target>
<perlscript mode="fg">

print "\nCleaning up file_permissions.db\n";

my $logfile = '/tmp/clean_file_permissions_log.txt';

# get a list of all user directories
print "Getting directory listing.\n";
my @dirs=`find <TARGET /> -type d `;
my @userdirs=grep(m|/[^/]*/[^/]*/[^/]*/[^/]*/[^/]*/[^/]*/[^/]*/[^/]*|, @dirs);

my $count = 0;
my $countby = 20;
print "Updating ".scalar(@userdirs)." files.  Each '.' represents ".$countby.
      " files processed.\n";
foreach my $udir (@userdirs) {
    if (++$count % $countby == 0) {
        print ".";
    }
    chomp($udir);
    my $file = $udir.'/file_permissions.db';
    next if (! -e $file);
    system('/home/httpd/perl/debug/clean_db.pl '.$file.
                ' "error%3a%202%20tie%28GDBM%29%20Failed%20while%20attempting%20dump" 2>>'.$logfile);
}
print "\nCompleted!\n";
</perlscript>
</file>
</files>
</piml>