Subversion Repositories DevTools

Rev

Rev 5743 | Rev 5783 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5743 Rev 5744
Line 1... Line -...
1
#! perl
-
 
2
########################################################################
1
########################################################################
3
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
4
#
3
#
5
# Module name   : cache_dpkg
4
# Module name   : cache_dpkg
6
# Module type   : Makefile system
5
# Module type   : JATS Utility
7
# Compiler(s)   : n/a
6
# Compiler(s)   : Perl
8
# Environment(s): jats
7
# Environment(s): jats
9
#
8
#
10
# Description:
9
# Description:
11
#       Maintain a local cache of dpkg_archive
10
#       Maintain a local cache of dpkg_archive
12
#
11
#
Line 49... Line 48...
49
my $opt_export;
48
my $opt_export;
50
my $opt_quiet;
49
my $opt_quiet;
51
my $opt_update_all;
50
my $opt_update_all;
52
my $opt_age;
51
my $opt_age;
53
my $opt_test;
52
my $opt_test;
-
 
53
my $opt_wait = 0;
54
 
54
 
55
#
55
#
56
#   Global Variables
56
#   Global Variables
57
#
57
#
58
my $GBE_DPKG            = $ENV{'GBE_DPKG'};                     # The Master repository
58
my $GBE_DPKG            = $ENV{'GBE_DPKG'};                     # The Master repository
Line 95... Line 95...
95
                "manual:3"                  => \$opt_help,
95
                "manual:3"                  => \$opt_help,
96
                "verbose:+"                 => \$opt_verbose,           # flag, multiple use allowed
96
                "verbose:+"                 => \$opt_verbose,           # flag, multiple use allowed
97
                "debug:+"                   => \$opt_debug,             # flag, multiple use allowed
97
                "debug:+"                   => \$opt_debug,             # flag, multiple use allowed
98
                "flush"                     => \$opt_flush,             # flag
98
                "flush"                     => \$opt_flush,             # flag
99
                "clear"                     => \$opt_clear,             # flag
99
                "clear"                     => \$opt_clear,             # flag
-
 
100
                "wait!"                     => \$opt_wait,              # [no]flag
100
                "refresh!"                  => \$opt_refresh,           # flag
101
                "refresh!"                  => \$opt_refresh,           # [no]flag
101
                "refresh_all|refresh-all"   => \$opt_refresh_all,       # flag
102
                "refresh_all|refresh-all"   => \$opt_refresh_all,       # flag
102
                "update_all|update-all"     => \$opt_update_all,        # flag
103
                "update_all|update-all"     => \$opt_update_all,        # flag
103
                "list"                      => \$opt_list,              # flag
104
                "list"                      => \$opt_list,              # flag
104
                "dir"                       => \$opt_list_short,        # flag
105
                "dir"                       => \$opt_list_short,        # flag
105
                "export"                    => \$opt_export,            # flag
106
                "export"                    => \$opt_export,            # flag
Line 130... Line 131...
130
#   Validate user options
131
#   Validate user options
131
#
132
#
132
Error( "GBE_BIN not defined in the environment" ) unless ( defined($GBE_BIN) );
133
Error( "GBE_BIN not defined in the environment" ) unless ( defined($GBE_BIN) );
133
Error( "GBE_DPKG not defined in the environment" ) unless ( defined($GBE_DPKG) );
134
Error( "GBE_DPKG not defined in the environment" ) unless ( defined($GBE_DPKG) );
134
 
135
 
-
 
136
$opt_refresh = 1
-
 
137
    if ( $opt_refresh_all );
-
 
138
 
135
#
139
#
136
#   No cache - nothing to do
140
#   Locate the various package stores
137
#   Generate a status message and exit
141
#   Search order for package should be:
-
 
142
#       DPKG_SANDBOX (Not cached)
-
 
143
#       DPKG_LOCAL   (To be deprecated)
-
 
144
#       DPKG_CACHE
-
 
145
#       DPKG_REPLICA
-
 
146
#       DPKG         (Writable to build system)
-
 
147
#       DPKG_STORE
138
#
148
#
-
 
149
$local = $GBE_DPKG_LOCAL;
139
unless ( defined($GBE_DPKG_CACHE) )
150
$cache = $GBE_DPKG_CACHE;
-
 
151
$istore = $GBE_DPKG_REPLICA;
-
 
152
$archive = $GBE_DPKG;
-
 
153
$gstore = $GBE_DPKG_STORE;
-
 
154
 
-
 
155
Error ("dpkg_archive cache is the main archive")    if ( $cache eq $archive );
-
 
156
Error ("dpkg_archive replica is the main archive")  if ( $istore && $istore eq $archive );
-
 
157
Error ("main archive is local archive" )            if ( $local && $local eq $archive );
-
 
158
Warning  ("dpkg_archive_cache is local_archive" )   if ( $cache && $local && $local eq $cache );
-
 
159
 
-
 
160
#
-
 
161
#   Perform package/version replication wait
-
 
162
#   
-
 
163
#   Do not need a cache for this to be performed as the operation is used on build servers
-
 
164
#   that do not have a cache (most Unix build machines)
-
 
165
#   
-
 
166
#   Cannot wait if we don't have a REPLICA
-
 
167
#   
-
 
168
if ($opt_wait && $istore)
140
{
169
{
-
 
170
    Verbose("Wait for package replication");
-
 
171
    #
-
 
172
    #   Scan the argument list
141
    Warning ( "GBE_DPKG_CACHE not defined in the environment" );
173
    #   Only wait for package/version. Cannot wait on an entire package
-
 
174
    #
142
    return 0;
175
    foreach (@ARGV)
143
}
176
    {
-
 
177
        unless (m~.+/.+~)
-
 
178
        {
-
 
179
            Verbose("Wait Skip $_");
-
 
180
            next;
-
 
181
        }
144
 
182
 
-
 
183
        if (-d "$istore/$_")
-
 
184
        {
-
 
185
            Verbose("Wait not required. Version in replica: $_");
-
 
186
            next;
-
 
187
        }
145
 
188
 
-
 
189
        unless (-d "$archive/$_")
-
 
190
        {
-
 
191
            Verbose("Wait not required. Version not in store: $_");
-
 
192
            next;
-
 
193
        }
-
 
194
 
-
 
195
        #
-
 
196
        #   Wait for the package to be replicated
-
 
197
        #       Wait up to 10 minutes
-
 
198
        #       Or the package to appear in the replica
-
 
199
        #       Or the package to disappear from the main store
-
 
200
        #
-
 
201
        Verbose("Waiting for replication of: $_");
-
 
202
        my $waitStart = time();
146
$opt_refresh = 1
203
        while (1)
-
 
204
        {
147
    if ( $opt_refresh_all );
205
            sleep(30);
-
 
206
            my $delta = time() - $waitStart;
-
 
207
            if (-d "$istore/$_")
-
 
208
            {
-
 
209
                Message("PkgReplication. Package replicated ($delta): $_");
-
 
210
                last;
-
 
211
            }
-
 
212
            unless (-d "$archive/$_")
-
 
213
            {
-
 
214
                Message("PkgReplication. Package deleted from main archive: $_");
-
 
215
                last;
-
 
216
            }
-
 
217
            #
-
 
218
            #   Done wait forever
-
 
219
            #   If the package has not been replicate we will just have to copy it the slow way
-
 
220
            #   
-
 
221
            if ( $delta >= 600)
-
 
222
            {
-
 
223
                Message("PkgReplication. Package not replicated: $_");
-
 
224
                last;
-
 
225
            }
-
 
226
        }
-
 
227
    }
-
 
228
}
148
 
229
 
149
#
230
#
150
#   Locate the archive cache
231
#   No cache - nothing to do
151
#
-
 
152
#   Determine the archive to work on
232
#   Generate a status message and exit
153
#   Search the cache archive list for one with the keyword "_cache"
-
 
154
#   or use the last one.
-
 
155
#
233
#
156
$GBE_DPKG =~ tr~\\/~/~s;
-
 
157
$GBE_DPKG =~ s~/$~~;
-
 
158
 
-
 
159
my @pkg_list = split ( ';', $GBE_DPKG_CACHE );
-
 
160
for (@pkg_list)
234
unless ( $cache )
161
{
235
{
162
    $cache = $_
236
    Warning ( "GBE_DPKG_CACHE not defined in the environment" );
163
        if ( m/_cache/ );
237
    exit 0;
164
}
238
}
165
$cache = pop @pkg_list unless ( $cache );
-
 
166
$archive = $GBE_DPKG;
-
 
167
$local = $GBE_DPKG_LOCAL;
-
 
168
$gstore = $GBE_DPKG_STORE;
-
 
169
$istore = $GBE_DPKG_REPLICA;
-
 
170
 
-
 
171
Error ("No dpkg_archive_cache found") unless ( $cache );
-
 
172
Error ("dpkg_archive_cache is the main archive") if ( $cache eq $archive );
-
 
173
Error ("dpkg_archive_image is the main archive") if ( $istore && $istore eq $archive );
-
 
174
Error ("main archive is local archive" )         if ( $local && $local eq $archive );
-
 
175
Warning  ("dpkg_archive_cache is local_archive" )   if ( $local && $local eq $cache );
-
 
176
 
239
 
177
#
240
#
178
#   Export the list of cache entries
241
#   Export the list of cache entries
179
#
242
#
180
if ( $opt_export or $opt_refresh_all or $opt_list_short or $opt_update_all )
243
if ( $opt_export or $opt_refresh_all or $opt_list_short or $opt_update_all )
Line 677... Line 740...
677
    -list              - List cache contents with nice format
740
    -list              - List cache contents with nice format
678
    -dir               - List cache contents
741
    -dir               - List cache contents
679
    -export            - Generate a list of cached packages
742
    -export            - Generate a list of cached packages
680
    -refresh_all       - Refresh all packages within the cache
743
    -refresh_all       - Refresh all packages within the cache
681
    -update_all        - Update all packages within the cache as required
744
    -update_all        - Update all packages within the cache as required
-
 
745
    -[no]wait          - Wait for package replication
682
    -quiet             - Suppress warnings
746
    -quiet             - Suppress warnings
683
    -age=nn            - Remove all packages older than nn days
747
    -age=nn            - Remove all packages older than nn days
684
    -test              - Use with -age to report ages
748
    -test              - Use with -age to report ages
685
 
749
 
686
=head1 OPTIONS
750
=head1 OPTIONS
Line 747... Line 811...
747
packages specified on the command line.
811
packages specified on the command line.
748
 
812
 
749
A package is deemed to be out-of-date if the modification time of the package's
813
A package is deemed to be out-of-date if the modification time of the package's
750
descpkg file in the cache is older than the one in the archive.
814
descpkg file in the cache is older than the one in the archive.
751
 
815
 
-
 
816
=item B<-[no]wait>
-
 
817
 
-
 
818
This option will cause the utility to wait for specified package versions to be replicated
-
 
819
into a package replica. The dafult mode is to not-wait, unless the operation is invoked 
-
 
820
from within the build phase.
-
 
821
 
-
 
822
The utility will wait upto 10 minutes (600 seconds) for a named version to be replicated
-
 
823
from the main archive to a replica.
-
 
824
 
-
 
825
A dpkg_cache need not be present for the replication-wait to be performed.
-
 
826
 
-
 
827
The wait-for replication step is designed to address an issue where the build system
-
 
828
is remotely located from the main archive. If required package versions are not in the
-
 
829
replica then this utility would copy them from the main archive. This can be very very 
-
 
830
slow - much slower than waiting for the replication to complete.
-
 
831
 
752
=item B<-quiet>
832
=item B<-quiet>
753
 
833
 
754
This option will suppress almost all of the progress messages, except for a single
834
This option will suppress almost all of the progress messages, except for a single
755
copy message. It is intended to be used when the program is called from another
835
copy message. It is intended to be used when the program is called from another
756
script.
836
script.