Subversion Repositories DevTools

Rev

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