pf-tools/pf-tools: ADDFILE: add 'AUTO:' shortcut in multiple sou...

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Wed Dec 10 11:50:39 UTC 2014


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/7e4dc70cbb7d
changeset: 1367:7e4dc70cbb7d
user:      melkor <melkor at sitadelle.com>
date:      Wed Dec 10 12:50:32 2014 +0100
description:
ADDFILE: add 'AUTO:' shortcut in multiple source definition that can search automatically file

diffstat:

 lib/PFTools/Update/ADDFILE.pm |  117 +++++++++++++++++++++++++----------------
 1 files changed, 71 insertions(+), 46 deletions(-)

diffs (143 lines):

diff -r ef99d1555fe7 -r 7e4dc70cbb7d lib/PFTools/Update/ADDFILE.pm
--- a/lib/PFTools/Update/ADDFILE.pm	Wed Dec 10 08:48:19 2014 +0100
+++ b/lib/PFTools/Update/ADDFILE.pm	Wed Dec 10 12:50:32 2014 +0100
@@ -53,6 +53,46 @@
     return;
 }
 
+sub __find_source {
+    my ( $ref_section, $options, $hash_subst ) = @_;
+
+    # search in order into:
+    # /SITE/pro1/FILE/pro1-ncdn-cache00/
+    # /SITE/pro1/FILE/pro1-ncdn-cache/
+    # /FILE/pro1-ncdn-cache00/
+    # /FILE/pro1-ncdn-cache/
+    # /SITE/pro1/FILE/ncdn-cache00/
+    # /SITE/pro1/FILE/ncdn-cache/
+    # /FILE/ncdn-cache00/
+    # /FILE/ncdn-cache/
+    # /FILE/common/
+
+    my @search_dirs = (
+        'HOSTNAMESITE', 'HOSTSITE',      'HOST',
+        'HOSTNAME',     'SHORTHOSTSITE', 'SHORTHOST',
+        'FILE:common/'
+    );
+
+    my $source;
+SEARCH_DIR:
+    foreach my $search_dir (@search_dirs) {
+        my @search_files = (
+            qq{$search_dir:%SECTIONNAME%.%HOSTDIGITS%},
+            qq{$search_dir:%SECTIONNAME%},
+        );
+        foreach my $search_file (@search_files) {
+            $source = get_source( $search_file,
+                $options->{'host'}, $hash_subst );
+            if ( -e $source ) {
+                $ref_section->{source} = $search_file;
+                last SEARCH_DIR;
+            }
+        }
+    }
+
+    return $source;
+}
+
 sub action_exec {
     my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
     my ( $source, $tmp );
@@ -61,61 +101,46 @@
     $hash_subst->{'SECTIONNAME'} = $dest;
     $tmp = get_tmp_dest($dest);
 
-    # Removing trailing space from source
     if ( !$ref_section->{'source'} ) {
-
-        # search in order into:
-        # /SITE/pro1/FILE/pro1-ncdn-cache00/
-        # /SITE/pro1/FILE/pro1-ncdn-cache/
-        # /FILE/pro1-ncdn-cache00/
-        # /FILE/pro1-ncdn-cache/
-        # /SITE/pro1/FILE/ncdn-cache00/
-        # /SITE/pro1/FILE/ncdn-cache/
-        # /FILE/ncdn-cache00/
-        # /FILE/ncdn-cache/
-        my @search_dirs = (
-            'HOSTNAMESITE', 'HOSTSITE',      'HOST',
-            'HOSTNAME',     'SHORTHOSTSITE', 'SHORTHOST',
-        );
-    SEARCH_DIR:
-        foreach my $search_dir (@search_dirs) {
-            my @search_files = (
-                qq{$search_dir:%SECTIONNAME%.%HOSTDIGITS%},
-                qq{$search_dir:%SECTIONNAME%},
-            );
-            foreach my $search_file (@search_files) {
-                $source = get_source( $search_file,
-                    $options->{'host'}, $hash_subst );
-                if ( -e $source ) {
-                    $ref_section->{source} = $search_file;
-                    last SEARCH_DIR;
-                }
-            }
-        }
+        $source = __find_source( $ref_section, $options, $hash_subst);
     }
     else {
+        # Removing trailing space from source
         $ref_section->{'source'} =~ s{\A\s*}{}xms;
         $ref_section->{'source'} =~ s{\s*\z}{}xms;
+        
         if ( $ref_section->{'source'} =~ m{\s}xms ) {
             $source = get_tmp_dest($dest) . q{.merged};
             unlink $source;
+        
+        SPLITSOURCE:
             foreach my $splitsource ( split q{ }, $ref_section->{'source'} ) {
-                $splitsource
-                    = get_source( $splitsource, $options->{'host'},
-                    $hash_subst );
-                if ( !-f $splitsource ) {
-                    carp colored(
-                        qq{ERROR: $splitsource no such file or directory},
-                        q{bold red on_white} );
-                    return;
-                }
-                if (deferredlogsystem(
-                        q{cat '} . $splitsource . q{' >> } . $source
-                    )
-                    )
-                {
-                    carp qq{ERROR: Unable to append $splitsource to $source};
-                    return;
+
+                if ( $splitsource =~ m{\AAUTO:(.*)\z}xms ) {
+                    $splitsource = __find_source( $1, $options, $hash_subst);
+                    
+                    if ( !-f $splitsource ) {
+                        next SPLITSOURCE;
+                    }
+
+                } else {
+                    $splitsource
+                        = get_source( $splitsource, $options->{'host'},
+                        $hash_subst );
+                    if ( !-f $splitsource ) {
+                        carp colored(
+                            qq{ERROR: $splitsource no such file or directory},
+                            q{bold red on_white} );
+                        return;
+                    }
+                    if (deferredlogsystem(
+                            q{cat '} . $splitsource . q{' >> } . $source
+                        )
+                        )
+                    {
+                        carp qq{ERROR: Unable to append $splitsource to $source};
+                        return;
+                    }
                 }
             }
         }



More information about the pf-tools-commits mailing list