[Fedora-directory-commits] ldapserver/ldap/admin/src/scripts Inf.pm, 1.5, 1.6 Migration.pm.in, 1.8, 1.9 Setup.pm.in, 1.12, 1.13

Richard Allen Megginson rmeggins at fedoraproject.org
Tue Feb 24 16:57:48 UTC 2009


Author: rmeggins

Update of /cvs/dirsec/ldapserver/ldap/admin/src/scripts
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv16618/ldapserver/ldap/admin/src/scripts

Modified Files:
	Inf.pm Migration.pm.in Setup.pm.in 
Log Message:
Resolves: bug 486474
Bug Description: overriding arguments to setup causes setup to fail
Reviewed by: ulf.weltman, nkinder (Thanks!)
Fix Description: Parameters specified on the command line should override and replace (not add to) any parameters specified in a given .inf file.  I refactored the code a little too - I moved the argv processing into the Inf module out of the Setup and Migration modules.  The code will first process the args and store the values in a temporary hash ref.  Then it will process the temp hash ref, replacing the values in the main inf with the values from the hash.
Platforms tested: RHEL4
Flag Day: no
Doc impact: no



Index: Inf.pm
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Inf.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Inf.pm	7 Sep 2007 15:02:25 -0000	1.5
+++ Inf.pm	24 Feb 2009 16:57:45 -0000	1.6
@@ -192,6 +192,60 @@
     close INF;
 }
 
+sub updateFromArgs {
+    my $self = shift;
+    my $argsinf = {}; # tmp for args read in
+
+    if (!@_) {
+        return 1; # no args - just return
+    }
+
+    # read args into temp inf
+    for (@_) {
+        if (/^([\w_-]+)\.([\w_-]+)=(.*)$/) { # e.g. section.param=value
+            my $sec = $1;
+            my $parm = $2;
+            my $val = $3;
+            # a single value is just a single scalar
+            # multiple values are represented by an array ref
+            if (exists($argsinf->{$sec}->{$parm})) {
+                if (!ref($argsinf->{$sec}->{$parm})) {
+                    # convert single scalar to array ref
+                    my $ary = [$argsinf->{$sec}->{$parm}];
+                    $argsinf->{$sec}->{$parm} = $ary;
+                }
+                # just push the new value
+                push @{$argsinf->{$sec}->{$parm}}, $val;
+            } else {
+                # single value
+                $argsinf->{$sec}->{$parm} = $val;
+            }
+        } else { # error
+            print STDERR "Error: unknown command line option $_\n";
+            return;
+        }
+    }
+
+    # no args read - just return true
+    if (!$argsinf || !%{$argsinf}) {
+        return 1;
+    }
+
+    # override inf with vals read from args
+    while (my ($name, $sec) = each %{$argsinf}) {
+        if (ref($sec) eq 'HASH') {
+            for my $key (keys %{$sec}) {
+                if (defined($sec->{$key})) {
+                    my $val = $sec->{$key};
+                    $self->{$name}->{$key} = $val;
+                }
+            }
+        }
+    }
+
+    return 1;
+}
+
 #############################################################################
 # Mandatory TRUE return value.
 #


Index: Migration.pm.in
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Migration.pm.in,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Migration.pm.in	10 Oct 2007 23:49:37 -0000	1.8
+++ Migration.pm.in	24 Feb 2009 16:57:45 -0000	1.9
@@ -232,14 +232,9 @@
     # see if user passed in default inf values - also, command line
     # arguments override those passed in via an inf file - this
     # allows the reuse of .inf files with some parameters overridden
-    for (@ARGV) {
-        if (/^([\w_-]+)\.([\w_-]+)=(.*)$/) { # e.g. section.param=value
-            $self->{inf}->{$1}->{$2} = $3;
-        } else { # error
-            print STDERR "Error: unknown command line option $_\n";
-            usage();
-            exit 1;
-        }
+    if (!$self->{inf}->updateFromArgs(@ARGV)) {
+        HelpMessage();
+        exit 1;
     }
 
     # this is the base config directory - the directory containing


Index: Setup.pm.in
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/Setup.pm.in,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Setup.pm.in	17 Dec 2008 18:28:04 -0000	1.12
+++ Setup.pm.in	24 Feb 2009 16:57:45 -0000	1.13
@@ -161,30 +161,9 @@
     # see if user passed in default inf values - also, command line
     # arguments override those passed in via an inf file - this
     # allows the reuse of .inf files with some parameters overridden
-    for (@ARGV) {
-        if (/^([\w_-]+)\.([\w_-]+)=(.*)$/) { # e.g. section.param=value
-            my $sec = $1;
-            my $parm = $2;
-            my $val = $3;
-            # a single value is just a single scalar
-            # multiple values are represented by an array ref
-            if (exists($self->{inf}->{$sec}->{$parm})) {
-                if (!ref($self->{inf}->{$sec}->{$parm})) {
-                    # convert single scalar to array ref
-                    my $ary = [$self->{inf}->{$sec}->{$parm}];
-                    $self->{inf}->{$sec}->{$parm} = $ary;
-                }
-                # just push the new value
-                push @{$self->{inf}->{$sec}->{$parm}}, $val;
-            } else {
-                # single value
-                $self->{inf}->{$sec}->{$parm} = $val;
-            }
-        } else { # error
-            print STDERR "Error: unknown command line option $_\n";
-            HelpMessage();
-            exit 1;
-        }
+    if (!$self->{inf}->updateFromArgs(@ARGV)) {
+        HelpMessage();
+        exit 1;
     }
 
     # this is the base config directory - the directory containing




More information about the Fedora-directory-commits mailing list