]> git.donarmstrong.com Git - debbugs.git/commitdiff
abstract out tie of binarytosource and sourcetobinary
authorDon Armstrong <don@donarmstrong.com>
Tue, 10 Apr 2018 23:12:04 +0000 (16:12 -0700)
committerDon Armstrong <don@donarmstrong.com>
Tue, 10 Apr 2018 23:12:04 +0000 (16:12 -0700)
Debbugs/Packages.pm

index 877466f91d2b4ce7f64c489546b0c34b79344a74..b332525c9b76bc79e9045701c2890687d90b68dc 100644 (file)
@@ -169,7 +169,19 @@ binary_to_source.
 # the two global variables below are used to tie the source maps; we
 # probably should be retying them in long lived processes.
 our %_binarytosource;
+sub _tie_binarytosource {
+    if (not tied %_binarytosource) {
+       tie %_binarytosource, MLDBM => $config{binary_source_map}, O_RDONLY or
+           die "Unable to open $config{binary_source_map} for reading";
+    }
+}
 our %_sourcetobinary;
+sub _tie_sourcetobinary {
+    if (not tied %_sourcetobinary) {
+       tie %_sourcetobinary, MLDBM => $config{source_binary_map}, O_RDONLY or
+           die "Unable to open $config{source_binary_map} for reading";
+    }
+}
 sub binary_to_source{
     my %param = validate_with(params => \@_,
                              spec   => {binary => {type => SCALAR|ARRAYREF,
@@ -270,10 +282,7 @@ sub binary_to_source{
            @{$param{cache}{$cache_key}};
     }
     for my $binary (@binaries) {
-       if (not tied %_binarytosource) {
-           tie %_binarytosource, MLDBM => $config{binary_source_map}, O_RDONLY or
-               die "Unable to open $config{binary_source_map} for reading";
-       }
+       _tie_binarytosource;
        # avoid autovivification
        my $bin = $_binarytosource{$binary};
        next unless defined $bin;
@@ -316,11 +325,7 @@ sub binary_to_source{
        # if any the packages we've been given are a valid source
        # package name, and there's no binary of the same name (we got
        # here, so there isn't), return it.
-
-       if (not tied %_sourcetobinary) {
-           tie %_sourcetobinary, MLDBM => $config{source_binary_map}, O_RDONLY or
-               die "Unable top open $gSourceBinaryMap for reading";
-       }
+       _tie_sourcetobinary();
        for my $maybe_sourcepkg (@binaries) {
            if (exists $_sourcetobinary{$maybe_sourcepkg}) {
                push @source,[$maybe_sourcepkg,$_] for keys %{$_sourcetobinary{$maybe_sourcepkg}};
@@ -374,14 +379,7 @@ returned, without the architecture.
 
 sub sourcetobinary {
     my ($srcname, $srcver) = @_;
-
-    if (not tied %_sourcetobinary) {
-       tie %_sourcetobinary, MLDBM => $config{source_binary_map}, O_RDONLY or
-           die "Unable top open $config{source_binary_map} for reading";
-    }
-
-
-
+    _tie_sourcetobinary;
     # avoid autovivification
     my $source = $_sourcetobinary{$srcname};
     return () unless defined $source;