[Reproducible-commits] [dpkg] 26/74: Dpkg::Conf: Add support for system and user config loading

Mattia Rizzolo mattia at debian.org
Sun Jul 3 22:22:54 UTC 2016


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to annotated tag 1.18.8
in repository dpkg.

commit 73c307b0d003149258efb620195ec03d08544378
Author: Guillem Jover <guillem at debian.org>
Date:   Mon Nov 3 19:36:46 2014 +0100

    Dpkg::Conf: Add support for system and user config loading
---
 debian/changelog     |  1 +
 scripts/Dpkg/Conf.pm | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index df76d26..41384a1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -19,6 +19,7 @@ dpkg (1.18.8) UNRELEASED; urgency=medium
       important for dpkg.cfg files, and duplicate option names stopped being
       supported. Add regression tests to avoid similar changes in the future.
       Closes: #824938
+    - Add support for system and user config loading in Dpkg::Conf.
   * Test suite:
     - Bump perlcritic ValuesAndExpressions::RequireNumberSeparators minimum
       to 99999.
diff --git a/scripts/Dpkg/Conf.pm b/scripts/Dpkg/Conf.pm
index bf9a613..1ef2581 100644
--- a/scripts/Dpkg/Conf.pm
+++ b/scripts/Dpkg/Conf.pm
@@ -100,6 +100,61 @@ sub set {
 
 Read options from a file. Return the number of options parsed.
 
+=item $conf->load_system_config($file)
+
+Read options from a system configuration file.
+
+Return the number of options parsed.
+
+=cut
+
+sub load_system_config {
+    my ($self, $file) = @_;
+
+    return 0 unless -e "$Dpkg::CONFDIR/$file";
+    return $self->load("$Dpkg::CONFDIR/$file");
+}
+
+=item $conf->load_user_config($file)
+
+Read options from a user configuration file. It will try to use the XDG
+directory, either $XDG_CONFIG_HOME/dpkg/ or $HOME/.config/dpkg/.
+
+Return the number of options parsed.
+
+=cut
+
+sub load_user_config {
+    my ($self, $file) = @_;
+
+    my $confdir = $ENV{XDG_CONFIG_HOME};
+    $confdir ||= $ENV{HOME} . '/.config' if length $ENV{HOME};
+
+    return 0 unless length $confdir;
+    return 0 unless -e "$confdir/dpkg/$file";
+    return $self->load("$confdir/dpkg/$file") if length $confdir;
+    return 0;
+}
+
+=item $conf->load_config($file)
+
+Read options from system and user configuration files.
+
+Return the number of options parsed.
+
+=cut
+
+sub load_config {
+    my ($self, $file) = @_;
+
+    my $nopts = 0;
+
+    $nopts += $self->load_system_config($file);
+    $nopts += $self->load_user_config($file);
+
+    return $nopts;
+}
+
 =item $conf->parse($fh)
 
 Parse options from a file handle. Return the number of options parsed.
@@ -196,6 +251,9 @@ Obsolete option: 'format_argv' in $conf->filter().
 
 Obsolete methods: $conf->get(), $conf->set().
 
+New methods: $conf->load_system_config(), $conf->load_system_user(),
+$conf->load_config().
+
 =head2 Version 1.02 (dpkg 1.18.5)
 
 New option: Accept new option 'format_argv' in $conf->filter().

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list