Subversion Repositories DevTools

Rev

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

Rev 1550 Rev 1552
Line 1170... Line 1170...
1170
#           the purposes of the filter the path starts with a '/'.
1170
#           the purposes of the filter the path starts with a '/'.
1171
#
1171
#
1172
#------------------------------------------------------------------------------
1172
#------------------------------------------------------------------------------
1173
{
1173
{
1174
    my $src_base_dir;
1174
    my $src_base_dir;
1175
    my $recurse = 1;
-
 
1176
    my @dir_tree_exclude;
-
 
1177
    my @dir_tree_include;
-
 
1178
    my $flatten = 0;
1175
    my $flatten = 0;
1179
    my $dstDir;
1176
    my $dstDir;
-
 
1177
    my $search =  LocateFiles->new(recurse => 1);
1180
 
1178
 
1181
    Information("Installing all Prepared pkg files...");
1179
    Information("Installing all Prepared pkg files...");
1182
    
1180
    
1183
    #
1181
    #
1184
    #   Process the arguments and extract parameters and options
1182
    #   Process the arguments and extract parameters and options
Line 1196... Line 1194...
1196
            Error("installAllDpkgArchivePkgFiles2: Multiple target directories not allowed")
1194
            Error("installAllDpkgArchivePkgFiles2: Multiple target directories not allowed")
1197
                if ( $dstDir );
1195
                if ( $dstDir );
1198
            $dstDir = $1;
1196
            $dstDir = $1;
1199
 
1197
 
1200
        } elsif ( m/^--NoRecurse/ ) {
1198
        } elsif ( m/^--NoRecurse/ ) {
1201
            $recurse = 0;
1199
            $search->recurse(0);
1202
 
1200
 
1203
        } elsif ( m/^--Recurse/ ) {
1201
        } elsif ( m/^--Recurse/ ) {
1204
            $recurse = 1;
1202
            $search->recurse(1);
1205
 
1203
 
1206
        } elsif ( /^--FilterOut=(.*)/ ) {
1204
        } elsif ( /^--FilterOut=(.*)/ ) {
1207
            push @dir_tree_exclude, glob2pat($1);
1205
            $search->filter_out( $1 );
1208
 
1206
 
1209
        } elsif ( /^--FilterOutRE=(.*)/ ) {
1207
        } elsif ( /^--FilterOutRE=(.*)/ ) {
1210
            push @dir_tree_exclude, $1;
1208
            $search->filter_out_re( $1 );
1211
 
1209
 
1212
        } elsif ( /^--FilterIn=(.*)/ ) {
1210
        } elsif ( /^--FilterIn=(.*)/ ) {
1213
            push @dir_tree_include, glob2pat($1);
1211
            $search->filter_in( $1 );
1214
 
1212
 
1215
        } elsif ( /^--FilterInRE=(.*)/ ) {
1213
        } elsif ( /^--FilterInRE=(.*)/ ) {
1216
            push @dir_tree_include, $1;
1214
            $search->filter_in_re( $1 );
1217
 
1215
 
1218
        } elsif ( /^--Flatten/ ) {
1216
        } elsif ( /^--Flatten/ ) {
1219
            $flatten = 1;
1217
            $flatten = 1;
1220
 
1218
 
1221
        } elsif ( /^--NoFlatten/ ) {
1219
        } elsif ( /^--NoFlatten/ ) {
Line 1252... Line 1250...
1252
    #   Build up a list of files to copy
1250
    #   Build up a list of files to copy
1253
    #   Creating a list allows:
1251
    #   Creating a list allows:
1254
    #       Simplified coding
1252
    #       Simplified coding
1255
    #       Flattening and testing of the flattening
1253
    #       Flattening and testing of the flattening
1256
    #
1254
    #
1257
    my @elements = ExpandDirTree( $src_base_dir, \@dir_tree_exclude, \@dir_tree_include, $recurse );
1255
    my @elements = $search->search( $src_base_dir);
1258
 
1256
 
1259
    #
1257
    #
1260
    #   Perform the file copy
1258
    #   Perform the file copy
1261
    #   This copy will NOT create empty directories, but it will create needed
1259
    #   This copy will NOT create empty directories, but it will create needed
1262
    #   directories on the fly.
1260
    #   directories on the fly.
Line 1313... Line 1311...
1313
    }
1311
    }
1314
 
1312
 
1315
    return 1;
1313
    return 1;
1316
}
1314
}
1317
 
1315
 
1318
#-------------------------------------------------------------------------------
-
 
1319
# Function        : glob2pat
-
 
1320
#
-
 
1321
# Description     : Convert four shell wildcard characters into their equivalent
-
 
1322
#                   regular expression; all other characters are quoted to
-
 
1323
#                   render them literals.
-
 
1324
#
-
 
1325
# Inputs          : Shell style wildcard pattern
-
 
1326
#
-
 
1327
# Returns         : Perl RE
-
 
1328
#
-
 
1329
 
-
 
1330
sub glob2pat
-
 
1331
{
-
 
1332
    my $globstr = shift;
-
 
1333
    $globstr =~ s~^/~~;
-
 
1334
    my %patmap = (
-
 
1335
        '*' => '[^/]*',
-
 
1336
        '?' => '[^/]',
-
 
1337
        '[' => '[',
-
 
1338
        ']' => ']',
-
 
1339
    );
-
 
1340
    $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
-
 
1341
    return '/' . $globstr . '$';
-
 
1342
}
-
 
1343
 
-
 
1344
#-------------------------------------------------------------------------------
-
 
1345
# Function        : ExpandDirTree
-
 
1346
#
-
 
1347
# Description     : Search a directory tree and return a list of files
-
 
1348
#                   that match the inclusion and exclusion filter
-
 
1349
#
-
 
1350
#                   The include filter is applied before the exclusuion filter
-
 
1351
#
-
 
1352
# Inputs          : $dir        - Directory to process
-
 
1353
#                   $exclude    - Ref to a List of regexps of files to exclude
-
 
1354
#                   $include    - Ref to a List of regexps of files to include
-
 
1355
#                   $recurse    - True: recurse subdirs
-
 
1356
#
-
 
1357
# Returns         : A list of files
-
 
1358
#
-
 
1359
my @ExpandDirTree_list;             # Must be global to avoid closure problems
-
 
1360
my $ExpandDirTree_len;
-
 
1361
 
-
 
1362
sub ExpandDirTree
-
 
1363
{
-
 
1364
    my( $dir, $exclude, $include, $recurse ) = @_;
-
 
1365
 
-
 
1366
    #
-
 
1367
    #   Clean up the user dir. Remove any trailing / as we will be adding it back
-
 
1368
    #
-
 
1369
    #
-
 
1370
    $dir =~ s~/*$~~g;
-
 
1371
 
-
 
1372
    #
-
 
1373
    #   Init recursion information
-
 
1374
    #   Needed to avoid closure interactions
-
 
1375
    #
-
 
1376
 
-
 
1377
    @ExpandDirTree_list = ();
-
 
1378
    $ExpandDirTree_len = length( $dir );
-
 
1379
 
-
 
1380
    #
-
 
1381
    #   Create a list of candidate files
-
 
1382
    #   If we are recursing the subtree, then this is a little harder
-
 
1383
    #   If we are not recursing then we can't simply glob the directory as
-
 
1384
    #   not all files are processed.
-
 
1385
    #
-
 
1386
    #   Will end up with a list of files that
-
 
1387
    #       1) Start with a '/'
-
 
1388
    #       2) Are rooted as $dir, but don't include $dir
-
 
1389
    #
-
 
1390
    if ( $recurse )
-
 
1391
    {
-
 
1392
        sub find_file_wanted
-
 
1393
        {
-
 
1394
            return if ( -d $_ );
-
 
1395
            my $file = $File::Find::name;
-
 
1396
            push @ExpandDirTree_list, substr($file, $ExpandDirTree_len );
-
 
1397
        }
-
 
1398
 
-
 
1399
        #
-
 
1400
        #       Under Unix we need to follow symbolic links, but Perl's
-
 
1401
        #       Find:find does not work with -follow under windows if the source
-
 
1402
        #       path contains a drive letter.
-
 
1403
        #
-
 
1404
        #       Solution. Only use follow under non-windows systems.
-
 
1405
        #                 Works as Windows does not have symlinks (yet).
-
 
1406
        #
-
 
1407
        my $follow_opt =  ! ( "$MachType" eq "win32" || "$MachType" eq "WinCE" );
-
 
1408
        
-
 
1409
        File::Find::find( {wanted => \&find_file_wanted, follow_fast => $follow_opt }, $dir);
-
 
1410
    }
-
 
1411
    else
-
 
1412
    {
-
 
1413
        local *DIR ;
-
 
1414
        opendir DIR, $dir || die ("Cannot open $dir");
-
 
1415
        foreach ( readdir( DIR ) )
-
 
1416
        {
-
 
1417
            next if /^\Q.\E$/;
-
 
1418
            next if /^\Q..\E$/;
-
 
1419
            next if ( -d "$dir/$_" );
-
 
1420
            push @ExpandDirTree_list, '/' . $_;
-
 
1421
 
-
 
1422
        }
-
 
1423
        closedir DIR;
-
 
1424
    }
-
 
1425
 
-
 
1426
    #
-
 
1427
    #   If filtering is not present then return the entire file list
-
 
1428
    #
-
 
1429
    return @ExpandDirTree_list
-
 
1430
        unless ( @$include || @$exclude );
-
 
1431
 
-
 
1432
    #
-
 
1433
    #   Filtering is present
-
 
1434
    #   Apply the filterin rules and then the filter out rules
-
 
1435
    #   If no filter-in rules, then assume that all files are allowed in and
-
 
1436
    #   simply apply the filter-out rules.
-
 
1437
    #
-
 
1438
    my @patsin  = map { qr/$_/ } @{$include};
-
 
1439
    my @patsout = map { qr/$_/ } @{$exclude};
-
 
1440
    my @result;
-
 
1441
 
-
 
1442
#    map { print "Include:$_\n"; } @{$include};
-
 
1443
#    map { print "Exclude:$_\n"; } @{$exclude};
-
 
1444
 
-
 
1445
 
-
 
1446
    file:
-
 
1447
    foreach my $file ( @ExpandDirTree_list )
-
 
1448
    {
-
 
1449
        if ( @$include )
-
 
1450
        {
-
 
1451
            my $in = 0;
-
 
1452
            for my $pat (@patsin)
-
 
1453
            {
-
 
1454
                if ( $file =~ /$pat/ )
-
 
1455
                {
-
 
1456
                    $in = 1;
-
 
1457
                    last;
-
 
1458
                }
-
 
1459
            }
-
 
1460
#print "------- Not included $file\n" unless $in;
-
 
1461
            next unless ( $in );
-
 
1462
        }
-
 
1463
 
-
 
1464
        for my $pat (@patsout)
-
 
1465
        {
-
 
1466
#print "------- REJECT $file :: $pat \n" if ( $file =~ /$pat/ );
-
 
1467
            next file if ( $file =~ /$pat/ );
-
 
1468
        }
-
 
1469
 
-
 
1470
        push @result, $file;
-
 
1471
    }
-
 
1472
 
-
 
1473
    return @result;
-
 
1474
}
-
 
1475
 
-
 
1476
#------------------------------------------------------------------------------
1316
#------------------------------------------------------------------------------
1477
sub installDpkgArchivePkgRaw
1317
sub installDpkgArchivePkgRaw
1478
#
1318
#
1479
# Description:
1319
# Description:
1480
#       This sub-routine is used to install all pkg files from the named package
1320
#       This sub-routine is used to install all pkg files from the named package
Line 1517... Line 1357...
1517
#       --NoWarn
1357
#       --NoWarn
1518
#           Supresses the warning message generated if no files are transferred
1358
#           Supresses the warning message generated if no files are transferred
1519
#
1359
#
1520
#------------------------------------------------------------------------------
1360
#------------------------------------------------------------------------------
1521
{
1361
{
1522
    my $recurse = 1;
-
 
1523
    my @dir_tree_exclude;
-
 
1524
    my @dir_tree_include;
-
 
1525
    my $flatten = 0;
1362
    my $flatten = 0;
1526
    my $dstDir;
1363
    my $dstDir;
1527
    my @args;
1364
    my @args;
1528
    my $src_base_dir;
1365
    my $src_base_dir;
1529
    my $warning = 1;
1366
    my $warning = 1;
-
 
1367
    my $search =  LocateFiles->new(recurse => 1);
1530
    
1368
    
1531
 
-
 
1532
    #
1369
    #
1533
    #   Process the arguments and extract parameters and options
1370
    #   Process the arguments and extract parameters and options
1534
    #
1371
    #
1535
    foreach ( @_ )
1372
    foreach ( @_ )
1536
    {
1373
    {
1537
        if ( m/^--NoRecurse/ ) {
1374
        if ( m/^--NoRecurse/ ) {
1538
            $recurse = 0;
1375
            $search->recurse(0);
1539
 
1376
 
1540
        } elsif ( m/^--Recurse/ ) {
1377
        } elsif ( m/^--Recurse/ ) {
1541
            $recurse = 1;
1378
            $search->recurse(1);
1542
 
1379
 
1543
        } elsif ( /^--FilterOut=(.*)/ ) {
1380
        } elsif ( /^--FilterOut=(.*)/ ) {
1544
            push @dir_tree_exclude, glob2pat($1);
1381
            $search->filter_out( $1 );
1545
 
1382
 
1546
        } elsif ( /^--FilterOutRE=(.*)/ ) {
1383
        } elsif ( /^--FilterOutRE=(.*)/ ) {
1547
            push @dir_tree_exclude, $1;
1384
            $search->filter_out_re( $1 );
1548
 
1385
 
1549
        } elsif ( /^--FilterIn=(.*)/ ) {
1386
        } elsif ( /^--FilterIn=(.*)/ ) {
1550
            push @dir_tree_include, glob2pat($1);
1387
            $search->filter_in( $1 );
1551
 
1388
 
1552
        } elsif ( /^--FilterInRE=(.*)/ ) {
1389
        } elsif ( /^--FilterInRE=(.*)/ ) {
1553
            push @dir_tree_include, $1;
1390
            $search->filter_in_re( $1 );
1554
 
1391
 
1555
        } elsif ( /^--Flatten/ ) {
1392
        } elsif ( /^--Flatten/ ) {
1556
            $flatten = 1;
1393
            $flatten = 1;
1557
 
1394
 
1558
        } elsif ( /^--NoFlatten/ ) {
1395
        } elsif ( /^--NoFlatten/ ) {
Line 1603... Line 1440...
1603
    #   Build up a list of files to copy
1440
    #   Build up a list of files to copy
1604
    #   Creating a list allows:
1441
    #   Creating a list allows:
1605
    #       Simplified coding
1442
    #       Simplified coding
1606
    #       Flattening and testing of the flattening
1443
    #       Flattening and testing of the flattening
1607
    #
1444
    #
1608
    my @elements = ExpandDirTree( $src_base_dir, \@dir_tree_exclude, \@dir_tree_include, $recurse );
1445
    my @elements = $search->search( $src_base_dir );
1609
    Information("Installing Raw Pkg files: $pkgName") if @elements;
1446
    Information("Installing Raw Pkg files: $pkgName") if @elements;
1610
 
1447
 
1611
    #
1448
    #
1612
    #   Perform the file copy
1449
    #   Perform the file copy
1613
    #   This copy will NOT create empty directories, but it will create needed
1450
    #   This copy will NOT create empty directories, but it will create needed
Line 3286... Line 3123...
3286
    #   If the source file contains a pattern, then expand the pattern
3123
    #   If the source file contains a pattern, then expand the pattern
3287
    #   This may result in multiple files.
3124
    #   This may result in multiple files.
3288
    #   Note: Allow for a single entry of the form
3125
    #   Note: Allow for a single entry of the form
3289
    #           --Filterin=xxx,---FilterOut=yyy
3126
    #           --Filterin=xxx,---FilterOut=yyy
3290
    #
3127
    #
-
 
3128
    my $search =  LocateFiles->new(recurse => 0);
3291
    my @flist;
3129
    my @flist;
3292
    my @dir_tree_exclude;
-
 
3293
    my @dir_tree_include;
-
 
3294
    foreach my $element ( @$fref )
3130
    foreach my $element ( @$fref )
3295
    {
3131
    {
3296
        foreach  ( split /,/ , $element )
3132
        foreach  ( split /,/ , $element )
3297
        {
3133
        {
3298
            if ( /^--FilterOut=(.*)/ ) {
3134
            if ( /^--FilterOut=(.*)/ ) {
3299
                push @dir_tree_exclude, glob2pat($1);
3135
                $search->filter_out( $1 );
3300
 
3136
 
3301
            } elsif ( /^--FilterOutRE=(.*)/ ) {
3137
            } elsif ( /^--FilterOutRE=(.*)/ ) {
3302
                push @dir_tree_exclude, $1;
3138
                $search->filter_out_re( $1 );
3303
 
3139
 
3304
            } elsif ( /^--FilterIn=(.*)/ ) {
3140
            } elsif ( /^--FilterIn=(.*)/ ) {
3305
                push @dir_tree_include, glob2pat($1);
3141
                $search->filter_in( $1 );
3306
 
3142
 
3307
            } elsif ( /^--FilterInRE=(.*)/ ) {
3143
            } elsif ( /^--FilterInRE=(.*)/ ) {
3308
                push @dir_tree_include, $1;
3144
                $search->filter_in_re( $1 );
3309
 
3145
 
3310
            } elsif ( m/^--/ ) {
3146
            } elsif ( m/^--/ ) {
3311
                Warning( "installDpkgArchiveLibFile: Unknown Filter option ignored: $_");
3147
                Warning( "installDpkgArchiveLibFile: Unknown Filter option ignored: $_");
3312
 
3148
 
3313
            } else {
3149
            } else {
Line 3317... Line 3153...
3317
    }
3153
    }
3318
 
3154
 
3319
    #
3155
    #
3320
    #   If any patterns have been found, then expand them
3156
    #   If any patterns have been found, then expand them
3321
    #
3157
    #
3322
    if ( @dir_tree_exclude || @dir_tree_include )
3158
    if ( $search->has_filter() )
3323
    {
3159
    {
3324
        foreach my $i (@{$DpkgLibDirList{$select}})
3160
        foreach my $i (@{$DpkgLibDirList{$select}})
3325
        {
3161
        {
3326
            my @elements = ExpandDirTree( "$DpkgLibDir/$i", \@dir_tree_exclude, \@dir_tree_include, 0 );
3162
            my @elements = $search->search( "$DpkgLibDir/$i" );
3327
 
3163
 
3328
            #
3164
            #
3329
            #   Clean off any leading / from each filename then add to a list
3165
            #   Clean off any leading / from each filename then add to a list
3330
            #   Remove any duplicates that were found
3166
            #   Remove any duplicates that were found
3331
            #
3167
            #
Line 6330... Line 6166...
6330
            close (FILE);
6166
            close (FILE);
6331
        }
6167
        }
6332
    }
6168
    }
6333
}
6169
}
6334
 
6170
 
6335
 
-
 
6336
#------------------------------------------------------------------------------
6171
#-------------------------------------------------------------------------------
6337
sub convertFile
6172
# Function        : convertFile
6338
#
-
 
6339
# Description:
-
 
6340
#       This sub-routine is used to remove all carrage return\line feeds
-
 
6341
#       from a line and replace them with the platform specific equivalent chars.
-
 
6342
#
6173
#
-
 
6174
# Description     : This sub-routine is used to remove all carrage return\line
-
 
6175
#                   feeds from a line and replace them with the platform
-
 
6176
#                   specific equivalent chars.
-
 
6177
#
6343
#       We let PERL determine what characters are written to the file base on the 
6178
#                   We let PERL determine what characters are written to the
6344
#       platform you are running on.
6179
#                   file base on the  platform you are running on.
-
 
6180
#
-
 
6181
#                   i.e. LF    for unix
-
 
6182
#                   CR\LF for win32
-
 
6183
#
-
 
6184
# Inputs          : m_targetDirTag          - Symbolic name of target directory
-
 
6185
#                   m_nfiles                - List of files in that directory
-
 
6186
#                   or
-
 
6187
#                   SearchOptions           - Search options to find files
-
 
6188
#                                           --Recurse
-
 
6189
#                                           --NoRecurse
-
 
6190
#                                           --FilterIn=xxx
-
 
6191
#                                           --FilterInRE=xxx
-
 
6192
#                                           --FilterOut=xxx
-
 
6193
#                                           --FilterOutRE=xxx
6345
#
6194
#
6346
#
6195
#
6347
#       i.e. LF    for unix
6196
# Returns         : 1
6348
#            CR\LF for win32
-
 
6349
#
6197
#
6350
#------------------------------------------------------------------------------
-
 
-
 
6198
sub convertFile
6351
{
6199
{
-
 
6200
    my @uargs;
-
 
6201
    my $search =  LocateFiles->new( recurse => 0 );
-
 
6202
 
-
 
6203
    #
6352
   # correct number of parameters?
6204
    #   Process user arguments extracting options
-
 
6205
    #
6353
    if ( ($#_+1) != 2 )
6206
    foreach  ( @_ )
6354
    {
6207
    {
6355
        Error("Incorrect number of params passed to " .
6208
        if ( m~^--Recurse~ ) {
6356
                  "convertFile() function. Check deploy config.");
-
 
6357
    }
-
 
6358
    my ($m_targetDirTag, $m_nfile) = @_;
6209
            $search->recurse(1);
6359
 
6210
 
-
 
6211
        } elsif ( m~^--NoRecurse~) {
-
 
6212
            $search->recurse(0);
6360
 
6213
 
6361
    # lets get the src dir value
6214
        } elsif ( /^--FilterOut=(.*)/ ) {
6362
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
6215
            $search->filter_out($1);
6363
 
-
 
6364
 
6216
 
6365
    # this is our file that we want to clean.
6217
        } elsif ( /^--FilterOutRE=(.*)/ ) {
6366
    my ($m_ifileLoc) = "$m_targetDirValue/$m_nfile";
6218
            $search->filter_out_re($1);
6367
    my ($m_tfileLoc) = "$m_targetDirValue/$m_nfile\.tmp";
-
 
6368
 
6219
 
-
 
6220
        } elsif ( /^--FilterIn=(.*)/ ) {
-
 
6221
            $search->filter_in($1);
6369
 
6222
 
6370
    # we will check to see if the file exists.
-
 
6371
    #
-
 
6372
    local *IFILE;
-
 
6373
    local *TFILE;
-
 
6374
    if ( -f "$m_ifileLoc" )
-
 
6375
    {
-
 
6376
        open (IFILE, "< $m_ifileLoc" ) or
6223
        } elsif ( /^--FilterInRE=(.*)/ ) {
6377
            Error("Failed to open file [$m_ifileLoc] : $!");
6224
            $search->filter_in_re($1);
6378
 
6225
 
6379
        open (TFILE, "> $m_tfileLoc" ) or
6226
        } elsif ( m~^--~) {
6380
            Error("Failed to open file [$m_tfileLoc] : $!");
6227
            Error ("convertFile: Unknown option: $_");
6381
 
6228
 
6382
        while ( <IFILE> ) 
-
 
6383
        {
-
 
6384
            chomp;
6229
        } else {
6385
            print TFILE "$_\n";
6230
            push @uargs, $_;
6386
        }
6231
        }
6387
    }
6232
    }
6388
    else
-
 
6389
    {
-
 
6390
        Error("Deploy file [$m_ifileLoc] does not exist.");
-
 
6391
    }
-
 
6392
 
6233
 
-
 
6234
    #
-
 
6235
    #   Process non-option arguments
6393
    close IFILE;
6236
    #       - Base dir
6394
    close TFILE;
6237
    #       - List of files
-
 
6238
    #
-
 
6239
    my ($m_targetDirTag, @m_nfiles) = @uargs;
-
 
6240
    Error ("convertFiles: Target Dir must be specified" ) unless ( $m_targetDirTag );
6395
 
6241
 
-
 
6242
    #
-
 
6243
    # Convert symbolic dir tag to physical path
-
 
6244
    #
-
 
6245
    my ($m_targetDirValue) = getTargetDstDirValue($m_targetDirTag, "A");
6396
 
6246
 
6397
    # lets replace our original file with the new one
-
 
6398
    #
6247
    #
-
 
6248
    #   Need to determine if we are searching or simply using a file list
-
 
6249
    #   There are two forms of the functions. If any of the search options have
6399
    if(File::Copy::move("$m_tfileLoc", "$m_ifileLoc"))
6250
    #   been used then we assume that we are searchine
-
 
6251
    #
-
 
6252
    if ( $search->has_filter() )
6400
    {
6253
    {
-
 
6254
        Error ("convertFiles: Cannot mix search options with named files") if ( @m_nfiles );
6401
        Information("Renamed [$m_tfileLoc] to [$m_ifileLoc] ...");
6255
        @m_nfiles = $search->search($m_targetDirValue);
6402
    }
6256
    }
-
 
6257
    Error ("convertFiles: No files specified") unless ( @m_nfiles );
-
 
6258
 
6403
    else
6259
    #
-
 
6260
    #   Process all named files
-
 
6261
    #
-
 
6262
    foreach my $m_nfile ( @m_nfiles )
6404
    {
6263
    {
-
 
6264
 
-
 
6265
        # this is our file that we want to clean.
-
 
6266
        my ($m_ifileLoc) = "$m_targetDirValue/$m_nfile";
-
 
6267
        my ($m_tfileLoc) = "$m_targetDirValue/$m_nfile\.tmp";
-
 
6268
 
-
 
6269
 
-
 
6270
        # we will check to see if the file exists.
-
 
6271
        #
-
 
6272
        local *IFILE;
-
 
6273
        local *TFILE;
-
 
6274
        if ( -f "$m_ifileLoc" )
-
 
6275
        {
-
 
6276
            open (IFILE, "< $m_ifileLoc" ) or
-
 
6277
                Error("Failed to open file [$m_ifileLoc] : $!");
-
 
6278
 
-
 
6279
            open (TFILE, "> $m_tfileLoc" ) or
-
 
6280
                Error("Failed to open file [$m_tfileLoc] : $!");
-
 
6281
 
-
 
6282
            while ( <IFILE> ) 
-
 
6283
            {
-
 
6284
                chomp;
-
 
6285
                print TFILE "$_\n";
-
 
6286
            }
-
 
6287
        }
-
 
6288
        else
-
 
6289
        {
-
 
6290
            Error("Deploy file [$m_ifileLoc] does not exist.");
-
 
6291
        }
-
 
6292
 
-
 
6293
        close IFILE;
-
 
6294
        close TFILE;
-
 
6295
 
-
 
6296
 
-
 
6297
        # lets replace our original file with the new one
-
 
6298
        #
-
 
6299
        if(File::Copy::move("$m_tfileLoc", "$m_ifileLoc"))
-
 
6300
        {
-
 
6301
            Information("Renamed [$m_tfileLoc] to [$m_ifileLoc] ...");
-
 
6302
        }
-
 
6303
        else
-
 
6304
        {
6405
        Error("Failed to rename file [$m_tfileLoc] to [$m_ifileLoc]: $!");
6305
            Error("Failed to rename file [$m_tfileLoc] to [$m_ifileLoc]: $!");
-
 
6306
        }
6406
    }
6307
    }
6407
 
6308
 
6408
    return 1;
6309
    return 1;
6409
}
6310
}
6410
 
6311
 
Line 7783... Line 7684...
7783
    }
7684
    }
7784
 
7685
 
7785
    return $src_base_dir;
7686
    return $src_base_dir;
7786
}
7687
}
7787
 
7688
 
-
 
7689
#===============================================================================
-
 
7690
#
-
 
7691
#   Internal Package
-
 
7692
#   An attempt to simplify the WildCardinf interface by capturing the parameters
-
 
7693
#   in a package. The idea is that storing the arguments can be easier
-
 
7694
#
-
 
7695
package LocateFiles;
-
 
7696
use JatsError;
-
 
7697
 
-
 
7698
#-------------------------------------------------------------------------------
-
 
7699
# Function        : new
-
 
7700
#
-
 
7701
# Description     : Create a new instance of a searcher
-
 
7702
#
-
 
7703
# Inputs          : 
-
 
7704
#
-
 
7705
# Returns         : 
-
 
7706
#
-
 
7707
sub new {
-
 
7708
    my $class = shift;
-
 
7709
    my $self  = {};
-
 
7710
    $self->{recurse}  = 0;
-
 
7711
    $self->{exclude}  = [];
-
 
7712
    $self->{include}  = [];
-
 
7713
    $self->{base_dir} = undef;
-
 
7714
    $self->{results}  = [];
-
 
7715
    bless ($self, $class);
-
 
7716
 
-
 
7717
    #
-
 
7718
    #   Process user arguments
-
 
7719
    #   These are are a hash
-
 
7720
    #
-
 
7721
    my %href = @_;
-
 
7722
    foreach my $entry ( keys %href )
-
 
7723
    {
-
 
7724
        Error( "LocateFiles:new. Unknown initialiser: $entry") unless ( exists $self->{$entry} );
-
 
7725
        $self->{$entry} = $href{$entry};
-
 
7726
    }
-
 
7727
    return $self;
-
 
7728
}
-
 
7729
 
-
 
7730
#-------------------------------------------------------------------------------
-
 
7731
# Function        : recurse
-
 
7732
#                   filter_in
-
 
7733
#                   filter_in_re
-
 
7734
#                   filter_out
-
 
7735
#                   filter_out_re
-
 
7736
#                   base_dir
-
 
7737
#                   results
-
 
7738
#
-
 
7739
# Description     : Accessor functions
-
 
7740
#
-
 
7741
# Inputs          : class
-
 
7742
#                   One argument (optional)
-
 
7743
#
-
 
7744
# Returns         : Current value of the daat item
-
 
7745
#
-
 
7746
sub recurse
-
 
7747
{
-
 
7748
    my $self = shift;
-
 
7749
    if (@_) { $self->{recurse} = shift }
-
 
7750
    return $self->{recurse};
-
 
7751
}
-
 
7752
 
-
 
7753
sub filter_in
-
 
7754
{
-
 
7755
    my $self = shift;
-
 
7756
    if (@_) { push @{$self->{include}}, glob2pat( shift ) }
-
 
7757
    return $self->{include};
-
 
7758
}
-
 
7759
 
-
 
7760
sub filter_in_re
-
 
7761
{
-
 
7762
    my $self = shift;
-
 
7763
    if (@_) { push @{$self->{include}}, shift }
-
 
7764
    return $self->{include};
-
 
7765
}
-
 
7766
 
-
 
7767
sub filter_out
-
 
7768
{
-
 
7769
    my $self = shift;
-
 
7770
    if (@_) { push @{$self->{exclude}}, glob2pat( shift ) }
-
 
7771
    return $self->{exclude};
-
 
7772
}
-
 
7773
 
-
 
7774
sub filter_out_re
-
 
7775
{
-
 
7776
    my $self = shift;
-
 
7777
    if (@_) { push @{$self->{exclude}}, shift }
-
 
7778
    return $self->{exclude};
-
 
7779
}
-
 
7780
 
-
 
7781
sub base_dir
-
 
7782
{
-
 
7783
    my $self = shift;
-
 
7784
    if (@_) { $self->{base_dir} = shift }
-
 
7785
    return $self->{base_dir};
-
 
7786
}
-
 
7787
 
-
 
7788
sub has_filter
-
 
7789
{
-
 
7790
    my $self = shift;
-
 
7791
    return ( ( @{$self->{include}} || @{$self->{exclude}} ) );
-
 
7792
}
-
 
7793
 
-
 
7794
 
-
 
7795
#-------------------------------------------------------------------------------
-
 
7796
# Function        : search
-
 
7797
#
-
 
7798
# Description     : This function performs the search for files as specified
-
 
7799
#                   by the arguments already provided
-
 
7800
#
-
 
7801
# Inputs          : base_dir (Optional)
-
 
7802
#
-
 
7803
# Returns         : List of files that match the search criteria
-
 
7804
#
-
 
7805
 
-
 
7806
my @search_list;             # Must be global to avoid closure problems
-
 
7807
my $search_len;
-
 
7808
 
-
 
7809
sub search
-
 
7810
{
-
 
7811
    my $self = shift;
-
 
7812
    $self->{base_dir} = $_[0] if (defined $_[0] );
-
 
7813
    $self->{results} = ();
-
 
7814
 
-
 
7815
    #
-
 
7816
    #   Ensure user has provided enough info
-
 
7817
    #
-
 
7818
    Error ("LocateFiles: No base directory provided") unless ( $self->{base_dir} );
-
 
7819
 
-
 
7820
    #
-
 
7821
    #   Clean up the user dir. Remove any trailing / as we will be adding it back
-
 
7822
    #
-
 
7823
    $self->{base_dir} =~ s~/*$~~g;
-
 
7824
 
-
 
7825
    #
-
 
7826
    #   Init recursion information
-
 
7827
    #   Needed to avoid closure interactions
-
 
7828
    #
-
 
7829
    @search_list = ();
-
 
7830
    $search_len = length( $self->{base_dir} );
-
 
7831
 
-
 
7832
    #
-
 
7833
    #   Create a list of candidate files
-
 
7834
    #   If we are recursing the subtree, then this is a little harder
-
 
7835
    #   If we are not recursing then we can't simply glob the directory as
-
 
7836
    #   not all files are processed.
-
 
7837
    #
-
 
7838
    #   Will end up with a list of files that
-
 
7839
    #       1) Start with a '/'
-
 
7840
    #       2) Are rooted as $dir, but don't include $dir
-
 
7841
    #
-
 
7842
    if ( $self->{recurse} )
-
 
7843
    {
-
 
7844
        sub find_file_wanted
-
 
7845
        {
-
 
7846
            return if ( -d $_ );
-
 
7847
            my $file = $File::Find::name;
-
 
7848
            push @search_list, substr($file, $search_len );
-
 
7849
        }
-
 
7850
 
-
 
7851
        #
-
 
7852
        #       Under Unix we need to follow symbolic links, but Perl's
-
 
7853
        #       Find:find does not work with -follow under windows if the source
-
 
7854
        #       path contains a drive letter.
-
 
7855
        #
-
 
7856
        #       Solution. Only use follow under non-windows systems.
-
 
7857
        #                 Works as Windows does not have symlinks (yet).
-
 
7858
        #
-
 
7859
        my $follow_opt =  ! ( "$MachType" eq "win32" || "$MachType" eq "WinCE" );
-
 
7860
        
-
 
7861
        File::Find::find( {wanted => \&find_file_wanted, follow_fast => $follow_opt }, $self->{base_dir} );
-
 
7862
    }
-
 
7863
    else
-
 
7864
    {
-
 
7865
        local *DIR ;
-
 
7866
        opendir DIR, $self->{base_dir} || die ("Cannot open $self->{base_dir}");
-
 
7867
        foreach ( readdir( DIR ) )
-
 
7868
        {
-
 
7869
            next if /^\Q.\E$/;
-
 
7870
            next if /^\Q..\E$/;
-
 
7871
            next if ( -d "$self->{base_dir}/$_" );
-
 
7872
            push @search_list, '/' . $_;
-
 
7873
 
-
 
7874
        }
-
 
7875
        closedir DIR;
-
 
7876
    }
-
 
7877
 
-
 
7878
    #
-
 
7879
    #   If filtering is not present then return the entire file list
-
 
7880
    #
-
 
7881
    $self->{results} = \@search_list ;
-
 
7882
    return @search_list
-
 
7883
        unless ( @{$self->{include}} || @{$self->{exclude}} );
-
 
7884
 
-
 
7885
    #
-
 
7886
    #   Filtering is present
-
 
7887
    #   Apply the filterin rules and then the filter out rules
-
 
7888
    #   If no filter-in rules, then assume that all files are allowed in and
-
 
7889
    #   simply apply the filter-out rules.
-
 
7890
    #
-
 
7891
    my @patsin  = map { qr/$_/ } @{$self->{include}};
-
 
7892
    my @patsout = map { qr/$_/ } @{$self->{exclude}};
-
 
7893
    my @result;
-
 
7894
 
-
 
7895
#    map { print "Include:$_\n"; } @{$self->{include}};
-
 
7896
#    map { print "Exclude:$_\n"; } @{$self->{exclude}};
-
 
7897
 
-
 
7898
 
-
 
7899
    file:
-
 
7900
    foreach my $file ( @search_list )
-
 
7901
    {
-
 
7902
        if ( @{$self->{include}} )
-
 
7903
        {
-
 
7904
            my $in = 0;
-
 
7905
            for my $pat (@patsin)
-
 
7906
            {
-
 
7907
                if ( $file =~ /$pat/ )
-
 
7908
                {
-
 
7909
                    $in = 1;
-
 
7910
                    last;
-
 
7911
                }
-
 
7912
            }
-
 
7913
#print "------- Not included $file\n" unless $in;
-
 
7914
            next unless ( $in );
-
 
7915
        }
-
 
7916
 
-
 
7917
        for my $pat (@patsout)
-
 
7918
        {
-
 
7919
#print "------- REJECT $file :: $pat \n" if ( $file =~ /$pat/ );
-
 
7920
            next file if ( $file =~ /$pat/ );
-
 
7921
        }
-
 
7922
 
-
 
7923
        push @result, $file;
-
 
7924
    }
-
 
7925
 
-
 
7926
    $self->{results} = \@result;
-
 
7927
#DebugDumpData ("Search", $self);
-
 
7928
    
-
 
7929
    return @result;
-
 
7930
}
-
 
7931
 
-
 
7932
#-------------------------------------------------------------------------------
-
 
7933
# Function        : glob2pat
-
 
7934
#
-
 
7935
# Description     : Convert four shell wildcard characters into their equivalent
-
 
7936
#                   regular expression; all other characters are quoted to
-
 
7937
#                   render them literals.
-
 
7938
#
-
 
7939
# Inputs          : Shell style wildcard pattern
-
 
7940
#
-
 
7941
# Returns         : Perl RE
-
 
7942
#
-
 
7943
 
-
 
7944
sub glob2pat
-
 
7945
{
-
 
7946
    my $globstr = shift;
-
 
7947
    $globstr =~ s~^/~~;
-
 
7948
    my %patmap = (
-
 
7949
        '*' => '[^/]*',
-
 
7950
        '?' => '[^/]',
-
 
7951
        '[' => '[',
-
 
7952
        ']' => ']',
-
 
7953
    );
-
 
7954
    $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
-
 
7955
    return '/' . $globstr . '$';
-
 
7956
}
-
 
7957
 
7788
#------------------------------------------------------------------------------
7958
#------------------------------------------------------------------------------
7789
1;
7959
1;