[LON-CAPA-cvs] cvs: loncom /build lpml_parse.pl

harris41 lon-capa-cvs@mail.lon-capa.org
Sun, 13 Oct 2002 17:27:49 -0000


harris41		Sun Oct 13 13:27:49 2002 EDT

  Modified files:              
    /loncom/build	lpml_parse.pl 
  Log:
  BUG 860; processing protectionlevel in order to implement the
  uninstall_shell_commands invocation mode; never_delete,
  weak_delete (rm -Rvf -i), and
  modest_delete+strong_delete+absolute_delete (rm -Rvf) are all supported;
  IMPORTANTLY, THIS SCRIPT WILL NEVER EVER IMPLEMENT DELETION OF THE
  ENTIRE FILESYSTEM (it traps 'rm -Rf /' possibilities which could result due
  to flawed xml files or xml parsing rules).
  
  
Index: loncom/build/lpml_parse.pl
diff -u loncom/build/lpml_parse.pl:1.50 loncom/build/lpml_parse.pl:1.51
--- loncom/build/lpml_parse.pl:1.50	Thu May 23 15:24:33 2002
+++ loncom/build/lpml_parse.pl	Sun Oct 13 13:27:49 2002
@@ -12,7 +12,7 @@
 # The LearningOnline Network with CAPA
 # lpml_parse.pl - Linux Packaging Markup Language parser
 #
-# $Id: lpml_parse.pl,v 1.50 2002/05/23 19:24:33 harris41 Exp $
+# $Id: lpml_parse.pl,v 1.51 2002/10/13 17:27:49 harris41 Exp $
 #
 # Written by Scott Harrison, codeharrison@yahoo.com
 #
@@ -47,6 +47,7 @@
 # 12/2,12/3,12/4,12/5,12/6,12/13,12/19,12/29 - Scott Harrison
 # YEAR=2002
 # 1/8,1/9,1/29,1/31,2/5,3/21,4/8,4/12 - Scott Harrison
+# 4/21,4/26,5/19,5/23,10/13 - Scott Harrison
 #
 ###
 
@@ -298,6 +299,7 @@
 my $directory;
 my $targetdirs;
 my $targetdir;
+my $protectionlevel;
 my $categoryname;
 my $description;
 my $files;
@@ -351,6 +353,7 @@
     category => \&format_category,
     abbreviation => \&format_abbreviation,
     targetdir => \&format_targetdir,
+    protectionlevel => \&format_protectionlevel,
     chown => \&format_chown,
     chmod => \&format_chmod,
     rpm => \&format_rpm,
@@ -974,6 +977,9 @@
     elsif ($mode eq 'rpm_file_list') {
 	return $text;
     }
+    elsif ($mode eq 'uninstall_shell_commands') {
+	return $text;
+    }
     else {
 	return '';
     }
@@ -981,7 +987,7 @@
 # ---------------------------------------------------- Format directory section
 sub format_directory {
     my (@tokeninfo)=@_;
-    $targetdir='';$categoryname='';$description='';
+    $targetdir='';$categoryname='';$description='';$protectionlevel='';
     $parser->get_text('/directory');
     $parser->get_tag('/directory');
     $directory_count++;
@@ -1015,6 +1021,36 @@
     elsif ($mode eq 'rpm_file_list') {
 	return $targetroot.'/'.$targetdir."\n";
     }
+    elsif ($mode eq 'uninstall_shell_commands') {
+	if ($protectionlevel eq 'never_delete') {
+	    return 'echo "LEAVING BEHIND '.$targetroot.'/'.$targetdir.
+		' which may have important data worth saving"'."\n";
+	}
+	elsif ($protectionlevel eq 'weak_delete') {
+	    if ($targetdir!~/\w/) {
+		die("targetdir=\"$targetdir\"! NEVER EVER DELETE THE WHOLE ".
+		    "FILESYSTEM"."\n");
+	    }
+	    return 'rm -Rvf -i '.$targetroot.'/'.$targetdir."\n";
+	}
+	elsif ($protectionlevel =~ /never/) {
+	    die("CONFUSING PROTECTION LEVEL \"$protectionlevel\" FOUND ".
+		"FOR directory $targetdir"."\n");
+	}
+	elsif ($protectionlevel !~
+    /^never_delete|weak_delete|modest_delete|strong_delete|absolute_delete$/) {
+	    die("CONFUSING OR MISSING PROTECTION LEVEL \"$protectionlevel\" ".
+		"FOUND FOR directory $targetdir\n");
+	}
+	else {
+	    if ($targetdir!~/\w/) {
+		die("targetdir=\"$targetdir\"! NEVER EVER DELETE THE WHOLE ".
+		    "FILESYSTEM"."\n");
+	    }
+	    return 'rm -Rvf '.$targetroot.'/'.$targetdir.
+		"| grep 'removed directory'"."\n";
+	}
+    }
     else {
 	return '';
     }
@@ -1027,6 +1063,17 @@
     if ($text) {
 	$parser->get_tag('/targetdir');
 	$targetdir=$text;
+    }
+    return '';
+}
+# ---------------------------------------------- Format protectionlevel section
+sub format_protectionlevel {
+    my @tokeninfo=@_;
+    $protectionlevel='';
+    my $text=&trim($parser->get_text('/protectionlevel'));
+    if ($text) {
+	$parser->get_tag('/protectionlevel');
+	$protectionlevel=$text;
     }
     return '';
 }