Subversion Repositories DevTools

Rev

Rev 5744 | Rev 5818 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
5709 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 3
#
4
# Module name   : cache_dpkg
5744 dpurdie 5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
227 dpurdie 7
# Environment(s): jats
8
#
9
# Description:
5743 dpurdie 10
#       Maintain a local cache of dpkg_archive
227 dpurdie 11
#
12
# Notes:
335 dpurdie 13
#       Stopped using the JATS "cp.exe" utility as there was a weird problem under
227 dpurdie 14
#       windows. The package orahops-ssw-install/1.0.1000.ssw could not be installed
335 dpurdie 15
#       correctly. It appears that the 'cp' could not process the subdir pair
227 dpurdie 16
#       "DBMGR/DBMGR". Change the name it was OK.
17
#
18
#       Solution: Avoid system functions
19
#
20
#......................................................................#
21
 
22
use strict;
23
use warnings;
24
use JatsError;
25
use FileUtils;
26
use File::Find;
27
use File::Path;
28
use File::Copy;
29
 
30
use Getopt::Long;
31
use Pod::Usage;                             # required for help support
32
 
5743 dpurdie 33
my $VERSION = "1.5.0";
227 dpurdie 34
 
35
 
36
#
37
#   Options
38
#
39
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
40
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
41
my $opt_help = 0;
42
my $opt_clear;
43
my $opt_flush;
44
my $opt_refresh;
45
my $opt_refresh_all;
46
my $opt_list;
47
my $opt_list_short;
48
my $opt_export;
49
my $opt_quiet;
50
my $opt_update_all;
51
my $opt_age;
361 dpurdie 52
my $opt_test;
5744 dpurdie 53
my $opt_wait = 0;
5783 dpurdie 54
my $opt_cache = 1;
227 dpurdie 55
 
56
#
57
#   Global Variables
58
#
4688 dpurdie 59
my $GBE_DPKG            = $ENV{'GBE_DPKG'};                     # The Master repository
60
my $GBE_DPKG_CACHE      = $ENV{'GBE_DPKG_CACHE'} || "";         # Caches
61
my $GBE_DPKG_LOCAL      = $ENV{'GBE_DPKG_LOCAL'} || "";         # Local scratch
62
my $GBE_DPKG_STORE      = $ENV{'GBE_DPKG_STORE'} || "";         # Global Store
63
my $GBE_DPKG_REPLICA    = $ENV{'GBE_DPKG_REPLICA'} || "";       # Site Local Replica
64
my $GBE_BIN             = $ENV{'GBE_BIN'};
227 dpurdie 65
 
4688 dpurdie 66
my $istore;
227 dpurdie 67
my $gstore;
68
my $archive;
69
my $cache;
70
my $parchive;
71
my $local = '';
72
my $local_pkg;
73
my @package_list;
74
my @refresh_list;
75
#
76
#   Globals for recursive copy
77
#
78
my $copyFind_dst;
79
my $copyFind_src;
80
my $copyFind_src_len;
81
 
82
#
83
#   Globals for error recovery
84
#
85
my  $remove_on_error;
86
 
87
#-------------------------------------------------------------------------------
88
# Function        : Mainline Entry Point
89
#
90
# Description     :
91
#
92
# Inputs          :
93
#
94
my $result = GetOptions (
337 dpurdie 95
                "help|h:+"                  => \$opt_help,
96
                "manual:3"                  => \$opt_help,
97
                "verbose:+"                 => \$opt_verbose,           # flag, multiple use allowed
98
                "debug:+"                   => \$opt_debug,             # flag, multiple use allowed
227 dpurdie 99
                "flush"                     => \$opt_flush,             # flag
100
                "clear"                     => \$opt_clear,             # flag
5744 dpurdie 101
                "wait!"                     => \$opt_wait,              # [no]flag
5783 dpurdie 102
                "cache!"                    => \$opt_cache,             # [no]flag
5744 dpurdie 103
                "refresh!"                  => \$opt_refresh,           # [no]flag
227 dpurdie 104
                "refresh_all|refresh-all"   => \$opt_refresh_all,       # flag
105
                "update_all|update-all"     => \$opt_update_all,        # flag
106
                "list"                      => \$opt_list,              # flag
107
                "dir"                       => \$opt_list_short,        # flag
108
                "export"                    => \$opt_export,            # flag
109
                "quiet"                     => \$opt_quiet,             # flag
110
                "age=i"                     => \$opt_age,               # integer
361 dpurdie 111
                "test"                      => \$opt_test,              # flag
227 dpurdie 112
                );
113
 
114
                #
115
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
116
                #
117
 
118
#
119
#   Process help and manual options
120
#
121
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
122
pod2usage(-verbose => 1)  if ($opt_help == 2 );
337 dpurdie 123
pod2usage(-verbose => 2)  if ($opt_help > 2);
227 dpurdie 124
 
125
#
126
#   Configure the error reporting process now that we have the user options
127
#
128
ErrorConfig( 'name'    =>'CACHE',
129
             'verbose' => $opt_verbose,
130
             'debug'   => $opt_debug );
131
 
132
#
133
#   Validate user options
134
#
135
Error( "GBE_BIN not defined in the environment" ) unless ( defined($GBE_BIN) );
136
Error( "GBE_DPKG not defined in the environment" ) unless ( defined($GBE_DPKG) );
137
 
5744 dpurdie 138
$opt_refresh = 1
139
    if ( $opt_refresh_all );
140
 
227 dpurdie 141
#
5744 dpurdie 142
#   Locate the various package stores
143
#   Search order for package should be:
144
#       DPKG_SANDBOX (Not cached)
145
#       DPKG_LOCAL   (To be deprecated)
146
#       DPKG_CACHE
147
#       DPKG_REPLICA
148
#       DPKG         (Writable to build system)
149
#       DPKG_STORE
227 dpurdie 150
#
5744 dpurdie 151
$local = $GBE_DPKG_LOCAL;
152
$cache = $GBE_DPKG_CACHE;
153
$istore = $GBE_DPKG_REPLICA;
154
$archive = $GBE_DPKG;
155
$gstore = $GBE_DPKG_STORE;
156
 
157
Error ("dpkg_archive cache is the main archive")    if ( $cache eq $archive );
158
Error ("dpkg_archive replica is the main archive")  if ( $istore && $istore eq $archive );
159
Error ("main archive is local archive" )            if ( $local && $local eq $archive );
160
Warning  ("dpkg_archive_cache is local_archive" )   if ( $cache && $local && $local eq $cache );
161
 
162
#
163
#   Perform package/version replication wait
164
#   
165
#   Do not need a cache for this to be performed as the operation is used on build servers
166
#   that do not have a cache (most Unix build machines)
167
#   
168
#   Cannot wait if we don't have a REPLICA
169
#   
170
if ($opt_wait && $istore)
227 dpurdie 171
{
5744 dpurdie 172
    Verbose("Wait for package replication");
173
    #
174
    #   Scan the argument list
175
    #   Only wait for package/version. Cannot wait on an entire package
176
    #
177
    foreach (@ARGV)
178
    {
179
        unless (m~.+/.+~)
180
        {
181
            Verbose("Wait Skip $_");
182
            next;
183
        }
227 dpurdie 184
 
5744 dpurdie 185
        if (-d "$istore/$_")
186
        {
187
            Verbose("Wait not required. Version in replica: $_");
188
            next;
189
        }
227 dpurdie 190
 
5744 dpurdie 191
        unless (-d "$archive/$_")
192
        {
193
            Verbose("Wait not required. Version not in store: $_");
194
            next;
195
        }
227 dpurdie 196
 
5744 dpurdie 197
        #
198
        #   Wait for the package to be replicated
199
        #       Wait up to 10 minutes
200
        #       Or the package to appear in the replica
201
        #       Or the package to disappear from the main store
202
        #
203
        Verbose("Waiting for replication of: $_");
204
        my $waitStart = time();
205
        while (1)
206
        {
207
            sleep(30);
208
            my $delta = time() - $waitStart;
209
            if (-d "$istore/$_")
210
            {
211
                Message("PkgReplication. Package replicated ($delta): $_");
212
                last;
213
            }
214
            unless (-d "$archive/$_")
215
            {
216
                Message("PkgReplication. Package deleted from main archive: $_");
217
                last;
218
            }
219
            #
220
            #   Done wait forever
221
            #   If the package has not been replicate we will just have to copy it the slow way
222
            #   
223
            if ( $delta >= 600)
224
            {
225
                Message("PkgReplication. Package not replicated: $_");
226
                last;
227
            }
228
        }
229
    }
230
}
231
 
227 dpurdie 232
#
5783 dpurdie 233
#   Allow replication update without also caching the package
234
#       This is used to prevent ALL replicated packages beinng cached.
235
#       Packages do not need to be cached if they are not used by a build on the current machine
236
#       This will prevent the cache from filling up with unused packages.
237
#
238
unless ($opt_cache)
239
{
240
    Message("Packages not cached");
241
    exit 0;
242
}
243
 
244
#
5744 dpurdie 245
#   No cache - nothing to do
246
#   Generate a status message and exit
227 dpurdie 247
#
5744 dpurdie 248
unless ( $cache )
227 dpurdie 249
{
5744 dpurdie 250
    Warning ( "GBE_DPKG_CACHE not defined in the environment" );
251
    exit 0;
227 dpurdie 252
}
253
 
254
#
255
#   Export the list of cache entries
256
#
257
if ( $opt_export or $opt_refresh_all or $opt_list_short or $opt_update_all )
258
{
259
    opendir (DIR, $cache) || die "Cannot open $cache\n";
260
    my @dir_list = readdir(DIR);
261
    closedir DIR;
262
 
263
    for my $fn ( @dir_list)
264
    {
265
        my $count = 0;
266
        next if ( $fn =~ m/^\./ );
267
        next unless ( -d "$cache/$fn" );
268
 
269
        opendir( DIR, "$cache/$fn" ) || die "Cannot open $cache/$fn\n";
270
        while ( my $fn1 = readdir(DIR) )
271
        {
272
            next if ( $fn1 =~ m/^\./ );
273
            push @package_list, "$fn/$fn1";
274
        }
275
        closedir DIR;
276
    }
277
 
278
    if ( $opt_refresh_all or $opt_update_all )
279
    {
280
        @refresh_list = @package_list
281
    }
282
 
283
    #
284
    #   Simply export a list of packages in the cache
285
    #   Used by other programs
286
    #
287
    if ( $opt_export )
288
    {
289
        print join ' ', @package_list;
290
        exit 0;
291
    }
292
}
293
 
294
#
295
#   Display cache information
296
#   This is done AFTER the export - since the export command does not
297
#   need this header.
298
if ( $opt_verbose || $#ARGV < 0 )
299
{
300
    print  "dpkg_store        : $gstore\n" if ($gstore);
301
    print  "dpkg_archive      : $archive\n";
4688 dpurdie 302
    print  "dpkg_archive image: $istore\n";
227 dpurdie 303
    print  "dpkg_archive cache: $cache\n";
304
    print  "dpkg_archive local: $local\n";
305
    Verbose ("args:               @ARGV");
306
}
307
 
308
#
309
#   List the contents of the cache
310
#
311
if ( $opt_list_short )
312
{
313
    print join "\n", @package_list;
314
}
315
 
316
if ( $opt_list )
317
{
318
    #
319
    #   Process user commands
320
    #   List: A nice pretty display of the cache
321
    #
322
    opendir (DIR, $cache) || die "Cannot open $cache\n";
323
    my @dir_list = readdir(DIR);
324
    closedir DIR;
325
 
326
    #
327
    #   Determine max length of a name so that the display is nicely aligned
328
    #
329
    my $nl = 10;
330
    for my $fn ( @dir_list)
331
    {
332
        my $ns = length($fn);
333
        $nl = $ns if ( $ns > $nl )
334
    }
335
 
336
    #
337
    #   Display information by package
338
    #   A nicely formatted list with line wrapping
339
    #
340
    for my $fn ( @dir_list)
341
    {
342
        my $count = 0;
343
        next if ( $fn =~ m/^\./ );
344
        next unless ( -d "$cache/$fn" );
345
 
346
        opendir( DIR, "$cache/$fn" ) || die "Cannot open $cache/$fn\n";
347
        printf "%-*s :", $nl, $fn;
348
        while ( my $fn1 = readdir(DIR) )
349
        {
350
            next if ( $fn1 =~ m/^\./ );
351
            if ( $count++ >= 4 )
352
            {
353
                $count = 1;
354
                printf "\n%*s  ", $nl, "";
355
            }
356
            printf " %14.14s", $fn1;
357
        }
358
        closedir DIR;
359
        print "\n";
360
    }
361
}
362
 
363
#
364
#   Clear the cache
365
#
366
if ( $opt_clear )
367
{
368
    Warning   ( "Deleting the ENTIRE cache");
369
    rmtree( $cache, $opt_debug );
370
    mkpath( $cache, $opt_debug, 0777);
371
}
372
 
373
#
374
#   Perform cache aging
375
#
376
if ( $opt_age )
377
{
378
    Error ("Age parameter cannot be negative") if ( $opt_age < 0 );
379
    age_the_cache();
380
}
381
 
382
#
383
#   Process the command line arguments
384
#   These MUST be of the form
385
#       packagename
386
#       packagename/version
387
#
388
 
389
for (@ARGV, @refresh_list)
390
{
391
    $remove_on_error = undef;
392
    if ( $opt_flush )
393
    {
394
        unless ( -d "$cache/$_" )
395
        {
396
            Warning ("Package not in cache: $_")
397
                unless ( $opt_quiet );
398
        }
399
        else
400
        {
401
            rmtree( "$cache/$_", $opt_debug );
402
            print "Package removed: $_\n"
403
                unless ( $opt_quiet );
404
        }
405
    }
406
    else
407
    {
408
        #
409
        #   Speed up - for remote access
410
        #   If the package is found in the local archive and we aren't doing
411
        #   anything fancy then don't access the remote archive
412
        #
413
        my $local_pkg = ( -d "$local/$_" || -f "$local/$_.lnk" );
414
        if ( $local_pkg )
415
        {
416
            if ( !$opt_refresh )
417
            {
418
                print "Cache SkipLocal: $_ Local copy found\n";
419
 
420
                #
421
                # Delete the cache copy
422
                # The user is playing with local copy
423
                #
424
                if ( -d "$cache/$_" )
425
                {
426
                    print  "Cache SkipLocalDelete: $_ -> $cache\n";
427
                    Verbose ( "Remove: $_" );
428
                    rmtree( "$cache/$_", $opt_debug );
429
                    Verbose ( "Remove Complete: $_" );
430
                }
431
                next;
432
            }
433
        }
434
 
435
        #
436
        #   Locate package.
4688 dpurdie 437
        #   It may be in GBE_DPKG_REPLICA, GBE_DPKG or GBE_DPKG_STORE
227 dpurdie 438
        #
4688 dpurdie 439
        my $pkg_found;
440
        foreach my $store ( $istore, $archive, $gstore)
227 dpurdie 441
        {
4688 dpurdie 442
            $parchive = "$store/$_";
443
            if ( -d $parchive )
227 dpurdie 444
            {
4688 dpurdie 445
                $pkg_found = 1;
446
                last;
227 dpurdie 447
            }
448
        }
4688 dpurdie 449
 
450
        unless ($pkg_found )
451
        {
452
            Warning ("Package not in archive: $_")
453
                unless ( $opt_quiet );
454
            next;
455
        }
227 dpurdie 456
 
457
        ########################################################################
458
        #   We have a package to process
459
        #
460
 
461
        my $dir_found = ( -d "$cache/$_" ) ;
462
        my $force_update = 0;
463
        my $opr = "Update";
464
 
465
 
466
        #
467
        #   Setup error recovery
335 dpurdie 468
        #       1) Tag the directory to be deleted on error
227 dpurdie 469
        #
470
        $remove_on_error = "$cache/$_";
471
        ErrorConfig( 'on_exit' => \&error_recovery );
472
 
473
        #
335 dpurdie 474
        #   Not a forced refresh. Ensure that the cached copy is
227 dpurdie 475
        #   up to date. Examine descpkg
476
        #
477
        if ( $dir_found )
478
        {
479
            if ( -f "$cache/$_/built.cache" )
480
            {
481
                $force_update = 1;
482
                $opr = "Incomplete";
483
                Verbose ("Cache Copy Incomplete: $_");
484
            }
485
            elsif ( FileIsNewer( "$parchive/descpkg", "$cache/$_/descpkg" ) )
486
            {
487
                $force_update = 1;
488
                $opr = "OutOfDate";
489
                Verbose ("Cache out-of-date: $_");
490
            }
491
        }
492
 
493
        #
494
        #   If we need to refresh the cache copy - delete it first
495
        #
496
        if ( ($opt_refresh || $force_update) && $dir_found )
497
        {
498
            print  "Cache $opr: $_ -> $cache\n";
499
            Verbose ( "Remove: $_" );
500
            rmtree( "$cache/$_", $opt_debug );
501
            Verbose ( "Remove Complete: $_" );
229 dpurdie 502
 
503
            #
504
            #   Force transfer, but without the status message
505
            #
227 dpurdie 506
            $dir_found = 0;
229 dpurdie 507
            $opr = '';
227 dpurdie 508
        }
509
 
510
        #
511
        #   If its not in the cache then copy it in
512
        #
513
        unless ( $dir_found )
514
        {
229 dpurdie 515
            print "Cache $opr: $_ -> $cache\n" if $opr;
227 dpurdie 516
            mkpath( "$cache/$_", $opt_debug, 0777);
517
            TouchFile ( "$cache/$_/built.cache", "Marks the cache copy as incomplete");
518
            Verbose ( "Copy in: $_" );
519
            $copyFind_dst = "$cache/$_";
520
            $copyFind_src = $parchive;
521
            $copyFind_src_len = length( $copyFind_src );
522
            File::Find::find( \&copyFind, $parchive );
523
            rmtree( "$cache/$_/built.cache", $opt_debug );  # Works on files too !!
524
        }
525
        else
526
        {
527
            $opr = "Skip";
528
            print "Cache $opr: $_ -> $cache\n";
529
        }
530
    }
531
}
532
 
533
#-------------------------------------------------------------------------------
534
# Function        : copyFind
535
#
536
# Description     : File:Find:find callback function to transfer files
537
#
538
# Inputs          : None
539
#                   Global: $copyFind_dst       : Target directory
540
#                   Global: $copyFind_src       : Source directory
541
#                   Global: $copyFind_src_len   : Length of Source dir
542
#
543
# Returns         : 
544
#
545
 
546
sub copyFind
547
{
548
    my $item = $File::Find::name;
549
 
550
    #
551
    #   Calculate the target directory name
552
    #
5743 dpurdie 553
    my $tgt_path = substr($item, $copyFind_src_len );
554
    my $target = $copyFind_dst . $tgt_path;
555
 
556
    # Do not cache some parts of a package when being used by the build system
557
    #   /lcov ...
558
    #
559
    if ( $ENV{GBE_ABT})
560
    {
561
        if ($tgt_path =~ m~^/lcov(/|$)~)
562
        {
563
            Verbose("Prune directory: $tgt_path");
564
            $File::Find::prune = 1;
565
            return;
566
        }
567
    }
568
 
227 dpurdie 569
    if ( -d $item )
570
    {
571
        #
572
        #   Directories are handled differently
573
        #       - Directories are created with nice permissions
574
        #
575
        if ( ! -d $target )
576
        {
577
            mkpath( $target, $opt_debug, 0755);
578
        }
579
    }
580
    else
581
    {
582
        #
583
        #   File copy
584
        #
585
        #
586
        #   Copy file to destination
587
        #   If the file is a link, then duplicate the link contents
588
        #   Use: Unix libraries are created as two files:
589
        #        lib.xxxx.so -> libxxxx.so.vv.vv.vv
590
        #
591
        if ( -l $item )
592
        {
593
            Debug("Clone Link: $target");
594
            my $link = readlink $item;
595
            Debug( "Link: $item, $link");
596
            symlink ($link, $target );
597
            unless ( $link && -l $target )
598
            {
599
                Error("Failed to copy link [$item] to [$target]: $!");
600
            }
601
        }
602
        elsif (File::Copy::copy($item, $target))
603
        {
604
            Debug("Copying File: $target");
605
 
606
            #   Make the file ReadOnly
607
            my $perm = (stat $item)[2] & 07777;
608
            CORE::chmod $perm & 0555, $target;
609
        }
610
        else
611
        {
612
            Error("Failed to copy file [$item] to [$target]: $!");
613
        }
614
    }
615
}
616
 
617
#-------------------------------------------------------------------------------
618
# Function        : error_recovery
619
#
620
# Description     : Error recovery routine
621
#                   Delete the cached entry
622
#
623
# Inputs          :  Globals
624
#
625
# Returns         : None
626
#
627
sub error_recovery
628
{
629
    if ( $remove_on_error )
630
    {
345 dpurdie 631
        ReportError ("Error cleanup. Delete cache entry: $remove_on_error");
227 dpurdie 632
        rmtree( $remove_on_error, $opt_debug );
633
        $remove_on_error = undef;
634
    }
635
}
636
 
637
 
638
#-------------------------------------------------------------------------------
639
# Function        : age_the_cache
640
#
641
# Description     : Age cache entries
642
#                   Determine the age by:
643
#                       Use used.cache file if present
644
#                       Use descpkg file
645
#                       Not a proper entry - delete
646
#
647
# Inputs          : opt_age         - Delete packages older than XX days
648
#
649
# Returns         : Nothing
650
#
651
sub age_the_cache
652
{
653
    my $now = time;
654
 
655
    opendir (DIR, $cache) || die "Cannot open $cache\n";
656
    my @dir_list = readdir(DIR);
657
    closedir DIR;
658
 
659
    for my $fn ( @dir_list)
660
    {
661
        my $keep_dir = 0;
662
        next if ( $fn =~ m/^\./ );
663
        next unless ( -d "$cache/$fn" );
361 dpurdie 664
        next if ( $fn eq "core_devl" );
227 dpurdie 665
 
666
        opendir( DIR, "$cache/$fn" ) || die "Cannot open $cache/$fn\n";
667
        while ( my $fn1 = readdir(DIR) )
668
        {
669
            next if ( $fn1 =~ m/^\./ );
670
            my $dir = "$cache/$fn/$fn1";
671
            my $file = "$dir/used.cache" ;
672
            $file = "$dir/descpkg" unless ( -f $file );
673
 
674
            if ( ! -f $file )
675
            {
676
                #
677
                #   No descpkg file
678
                #   This is a badly formed entry - so delete it
679
                #
361 dpurdie 680
                if ( $opt_test )
681
                {
682
                    Message("Would Purge: $fn/$fn1" );
683
                    $keep_dir = 1;
684
                }
685
                else
686
                {
687
                    Message("Purging: $fn/$fn1" );
688
                    rmtree( $dir, $opt_debug );
689
                }
227 dpurdie 690
            }
691
            else
692
            {
693
                #
694
                #   used.cache or descpkg file found
695
                #   How old is it
696
                #
697
                my $timestamp = (stat($file))[9] || 0;
698
                my $age = int( ($now - $timestamp) / (60 * 60 * 24));
699
 
700
                if ( $age > $opt_age )
701
                {
361 dpurdie 702
                    if ( $opt_test )
703
                    {
704
                        Message("Could Age: $fn/$fn1, $age" );
705
                        $keep_dir = 1;
706
                    } else {
707
                        Message("Aging: $fn/$fn1, $age" );
708
                        rmtree( $dir, $opt_debug );
709
                    }
227 dpurdie 710
                }
711
                else
712
                {
713
                    Verbose("Age of: $fn/$fn1, $age" );
714
                    $keep_dir = 1;
715
                }
716
            }
717
        }
718
        closedir DIR;
719
 
720
        #
721
        #   Delete the entire directory if is is empty
722
        #
723
        unless ( $keep_dir )
724
        {
725
            Message("Remove Empty Dir: $cache/$fn"  );
726
            rmtree( "$cache/$fn", $opt_debug );
727
        }
728
    }
729
}
730
 
731
#-------------------------------------------------------------------------------
732
#   Documentation
733
#
734
 
735
=pod
736
 
361 dpurdie 737
=for htmltoc    SYSUTIL::
738
 
227 dpurdie 739
=head1 NAME
740
 
741
cache_dpkg - Maintain a local cache of packages
742
 
743
=head1 SYNOPSIS
744
 
745
 jats cache_dpkg.pl [options] package/version ...
746
 
747
 Options:
748
    -help              - brief help message
749
    -help -help        - Detailed help message
750
    -man               - Full documentation
751
    -clear             - Delete the entire cache
752
    -flush             - Flush all named packages
753
    -[no]refresh       - Refresh package in cache
754
    -list              - List cache contents with nice format
755
    -dir               - List cache contents
756
    -export            - Generate a list of cached packages
757
    -refresh_all       - Refresh all packages within the cache
758
    -update_all        - Update all packages within the cache as required
5744 dpurdie 759
    -[no]wait          - Wait for package replication
5783 dpurdie 760
    -[no]cache         - Cache packages [default]
227 dpurdie 761
    -quiet             - Suppress warnings
361 dpurdie 762
    -age=nn            - Remove all packages older than nn days
763
    -test              - Use with -age to report ages
227 dpurdie 764
 
765
=head1 OPTIONS
766
 
767
=over 8
768
 
769
=item B<-help>
770
 
771
Print a brief help message and exits.
772
 
773
=item B<-help -help>
774
 
775
Print a detailed help message with an explanation for each option.
776
 
777
=item B<-man>
778
 
779
Prints the manual page and exits.
780
 
781
=item B<-clear>
782
 
783
Delete the B<entire> contents of the dpkg_archive cache. This will occur before
784
any new packages are copied into the cache.
785
 
786
=item B<-flush>
787
 
788
If set then the utility will delete the named packages from the cache. All named
789
packaged will be deleted. This option affects all named packages. It is not
790
possible to flush and copy packages with the same command.
791
 
792
=item B<-[no]refresh>
793
 
794
If the B<refresh> option has been specified then packages will be deleted, from
795
the cache and then a new copy will be copied in. If not specified then no copy
796
will occur if the package is present in the cache.
797
 
798
=item B<-list>
799
 
800
Display a list of all packages in the cache. A formatted display is generated.
801
 
802
This will be done before any packages are transferred.
803
 
804
=item B<-dir>
805
 
806
Display a list of all packages in the cache. This is a raw directory like
807
listing of the cache.
808
 
809
This will be done before any packages are transferred.
810
 
811
=item B<-export>
812
 
813
Generate a space separated list of cached packages as a single line. This is
814
intended to allow a list be exported for later import.
815
 
816
=item B<-refresh_all>
817
 
818
This option will force the program to refresh all the packages in the cache.
819
This forces a B<-refresh> and may be combined with other packages specified
820
on the command line.
821
 
822
=item B<-update_all>
823
 
824
This option will force the program to examine all packages within the cache and
825
refresh packages that are out of date. This option may be combined with other
826
packages specified on the command line.
827
 
828
A package is deemed to be out-of-date if the modification time of the package's
335 dpurdie 829
descpkg file in the cache is older than the one in the archive.
227 dpurdie 830
 
5744 dpurdie 831
=item B<-[no]wait>
832
 
833
This option will cause the utility to wait for specified package versions to be replicated
834
into a package replica. The dafult mode is to not-wait, unless the operation is invoked 
835
from within the build phase.
836
 
837
The utility will wait upto 10 minutes (600 seconds) for a named version to be replicated
838
from the main archive to a replica.
839
 
840
A dpkg_cache need not be present for the replication-wait to be performed.
841
 
842
The wait-for replication step is designed to address an issue where the build system
843
is remotely located from the main archive. If required package versions are not in the
844
replica then this utility would copy them from the main archive. This can be very very 
845
slow - much slower than waiting for the replication to complete.
846
 
5783 dpurdie 847
=item B<-[no]cache>
848
 
849
This option can be used to prevent the named packages from being cached. The default mode
850
is to cache the named packages.
851
 
852
It is intended to be used with the '-wait' option so that replication is complete
853
but the local caching is not perform. To be used for non-ant builds to prevent local caching
854
of packages that are not used in a build.
855
 
227 dpurdie 856
=item B<-quiet>
857
 
858
This option will suppress almost all of the progress messages, except for a single
859
copy message. It is intended to be used when the program is called from another
860
script.
861
 
862
=item B<-age=nn>
863
 
864
This option will delete all package versions that are older than the nn days.
865
The age of a package is calculated from the timestamp of the descpkg file.
866
 
361 dpurdie 867
=item B<-test>
868
 
869
This option modifies the operation of the B<-age=nn> option such that it will not
870
delete old package-versions. It will simply report what would be deleted.
871
 
227 dpurdie 872
=back
873
 
874
=head1 DESCRIPTION
875
 
876
This program simplifies the operation of maintaining a local copy of
877
used packages from the maintaining dpkg_archive store. The cache should be
878
stored on your local disk for speed.
879
 
880
=head2 Location of the cache
881
 
4688 dpurdie 882
The local cache is specified with the EnvVar GBE_DPKG_CACHE
227 dpurdie 883
 
4688 dpurdie 884
=head2 Location of the maintaining archive
227 dpurdie 885
 
4688 dpurdie 886
The required pacjage version can be found in three archives. These are:
227 dpurdie 887
 
4688 dpurdie 888
=over 4
227 dpurdie 889
 
4688 dpurdie 890
=item *
227 dpurdie 891
 
4688 dpurdie 892
GBE_DPKG_REPLICA. A local image of the main dpkg_archive. This is used when dpkg_archive is synced locally and is expected to be faster than GBE_DPKG
893
 
894
=item *
895
 
896
GBE_DPKG. The main dpkg_archive
897
 
898
=item *
899
 
900
GBE_DPKG_STORE. A global package archive. The search repository of last choice.
901
 
902
=back
903
 
227 dpurdie 904
=head2 Interaction with local_dpkg_archive
905
 
906
If a package is located in the users local_dpkg_archive and we are doing a
907
simple cache update then the package will be deleted from the cache. This is
908
done to speed use on slow remote links and ensure cache consistency.
909
 
5743 dpurdie 910
=head2 Interaction with build system
911
 
912
If the cache operating is done withinthe context of the Build System (GBE_ABT is not zero), 
913
then some parts of the package will not be transferred. This is done to speed up the caching.
914
 
915
Directories that will not be cached:
916
 
917
=over 4
918
 
919
=item * 
920
 
921
lcov - A directory that contains code coverage information. This directory normally 
922
contains a large number of files, none of which are used by the build system. Over long 
923
links the trasnfer time of the 'lcov' directory can take hours.
924
 
925
=back
926
 
227 dpurdie 927
=head1 EXAMPLE
928
 
929
=head2 jats dpkg_cache -list
930
 
931
This will list the current contents of the cache.
932
 
933
=head2 jats dpkg_cache -refresh crc/1.0.4.cr
934
 
935
This will delete any cached copy of the package crc/1.0.4.cr, if one exists,
936
and then copy in a new version.
937
 
938
=head2 jats dpkg_cache crc
939
 
940
This will copy in all versions of the crc package. This may not be desirable.
941
 
942
=head2 jats dpkg_cache -update_all
943
 
944
This will examine all packages in the cache and refresh those packages that are
945
out of date.
946
 
947
=cut
948