Subversion Repositories DevTools

Rev

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

Rev 4635 Rev 4636
Line 36... Line 36...
36
#                       CopyFile                - Copy a file
36
#                       CopyFile                - Copy a file
37
#                       CopyBinFile             - Copy an executable file
37
#                       CopyBinFile             - Copy an executable file
38
#                       CopyLibFile             - Copy a library file
38
#                       CopyLibFile             - Copy a library file
39
#                       CreateDir               - Create a directory
39
#                       CreateDir               - Create a directory
40
#                       DebianFiles             - Specify control and script files
40
#                       DebianFiles             - Specify control and script files
-
 
41
#                       DebianControlFile       - Specify control and script files
-
 
42
#                       DebianDepends           - Add Depends entry to control file
41
#                       EchoFile                - Place text into a file
43
#                       EchoFile                - Place text into a file
42
#                       MakeSymLink             - Create a symbolic link
44
#                       MakeSymLink             - Create a symbolic link
43
#                       PackageDescription      - Specify the package description
45
#                       PackageDescription      - Specify the package description
44
#                       SetFilePerms            - Set file permissions
46
#                       SetFilePerms            - Set file permissions
45
#                       SetVerbose              - Control progress display
47
#                       SetVerbose              - Control progress display
Line 71... Line 73...
71
use File::Copy;
73
use File::Copy;
72
use File::Find;
74
use File::Find;
73
use JatsSystem;
75
use JatsSystem;
74
use FileUtils;
76
use FileUtils;
75
use JatsError;
77
use JatsError;
-
 
78
use JatsLocateFiles;
76
use ReadBuildConfig;
79
use ReadBuildConfig;
77
use JatsCopy ();                            # Don't import anything
80
use JatsCopy ();                            # Don't import anything
78
 
81
 
79
#
82
#
80
#   Globals
83
#   Globals
Line 373... Line 376...
373
    #
376
    #
374
    Verbose ("UpdateControlFile: $dst" );
377
    Verbose ("UpdateControlFile: $dst" );
375
    $src = ResolveFile( 0, $src );
378
    $src = ResolveFile( 0, $src );
376
 
379
 
377
    #   Calc depends line
380
    #   Calc depends line
378
    my $depData = join (',', @DependencyList );
381
    my $depData = join (', ', @DependencyList );
379
 
382
 
380
    open (SF, '<', $src) || Error ("UpdateControlFile: Cannot open:$src, $!");
383
    open (SF, '<', $src) || Error ("UpdateControlFile: Cannot open:$src, $!");
381
    open (DF, '>', $dst) || Error ("UpdateControlFile: Cannot create:$dst, $!");
384
    open (DF, '>', $dst) || Error ("UpdateControlFile: Cannot create:$dst, $!");
382
    while ( <SF> )
385
    while ( <SF> )
383
    {
386
    {
Line 424... Line 427...
424
{
427
{
425
    my $dst = "$DebianWorkDir/DEBIAN/control";
428
    my $dst = "$DebianWorkDir/DEBIAN/control";
426
 
429
 
427
    Verbose ("CreateControlFile: $dst" );
430
    Verbose ("CreateControlFile: $dst" );
428
 
431
 
429
    my $depData = join (',', @DependencyList );
432
    my $depData = join (', ', @DependencyList );
430
 
433
 
431
    open (DF, '>', $dst) || Error ("CreateControlFile: Cannot create:$dst");
434
    open (DF, '>', $dst) || Error ("CreateControlFile: Cannot create:$dst");
432
    print DF "Package: $opt_name\n";
435
    print DF "Package: $opt_name\n";
433
    print DF "Version: $opt_buildversion\n";
436
    print DF "Version: $opt_buildversion\n";
434
    print DF "Section: main\n";
437
    print DF "Section: main\n";
Line 556... Line 559...
556
# Function        : DebianDepends 
559
# Function        : DebianDepends 
557
#
560
#
558
# Description     : This directive allows simple dependency information to be  
561
# Description     : This directive allows simple dependency information to be  
559
#                   inserted into the control file
562
#                   inserted into the control file
560
#
563
#
561
#                   Note useful in embedded system
564
#                   Not useful in embedded system
562
#
565
#
563
# Inputs          : Entry             - A dependency entry
566
# Inputs          : Entry             - A dependency entry
564
#                   ...               - More entries
567
#                   ...               - More entries
565
#                   
568
#                   
566
#
569
#
Line 1215... Line 1218...
1215
        }
1218
        }
1216
    }
1219
    }
1217
}
1220
}
1218
 
1221
 
1219
#-------------------------------------------------------------------------------
1222
#-------------------------------------------------------------------------------
-
 
1223
# Function        : SetPermissions 
-
 
1224
#
-
 
1225
# Description     : Called to set permissions of files/dirs in a directory structure.
-
 
1226
#                   With no options sets DirTag and all files/dirs in it to perms
-
 
1227
#   
-
 
1228
# Inputs          : path        - The directory tag to start setting permissions on
-
 
1229
#                   Options     - See below
-
 
1230
#       
-
 
1231
#   Required Options:
-
 
1232
#       One or both of
-
 
1233
#               --FilePerms=    Sets the permissions of files to this permission.
-
 
1234
#                               If not supplied then no files have their permissions changed
-
 
1235
#               --DirPerms=     Sets the permissions of directories to this permission
-
 
1236
#                               If not supplied then no directories have their permissions changed
-
 
1237
#       OR
-
 
1238
#               --Perms=        Sets the permissions of both files and directories to this permissions
-
 
1239
#                               Equivalent to supplying both --FilePerms=X && --DirPerms=X
-
 
1240
#               
-
 
1241
#   Options:                    
-
 
1242
#               --RootOnly      Only sets the permissions on the 'path' directory/file, 
-
 
1243
#                               all other options ignored
-
 
1244
#               --SkipRoot      Does not set permissions on the 'path' directory/file, 
-
 
1245
#                               obviously mutually exlusive with --RootOnly
-
 
1246
#   
-
 
1247
#       Any option supported by JatsLocateFiles. 
-
 
1248
#       Some of these include:
-
 
1249
#               
-
 
1250
#               --Recurse       Recurse the directory tree.  Does a depth first recurse so that all 
-
 
1251
#                               dir entries are processed before the dir itself (default)
-
 
1252
#               --NoRecurse     Dont recurse
-
 
1253
#               --FilterIn=     Apply permissions to files/directories that matches this value.
-
 
1254
#               --FilterInRe=   Perl RE's can be used (Not Shell wildcards) and this option
-
 
1255
#                               can be supplied mulitple times
-
 
1256
#               --FilterOut=    Dont apply permissions to any files/directories matching this value
-
 
1257
#               --FilterOutRe=  Perl RE's can be used (Not Shell wildcards) and this option
-
 
1258
#                               can be supplied mulitple times
-
 
1259
#               
-
 
1260
#                               FilterIn is applied before FilterOut.  If Recurse is specified 
-
 
1261
#                               the directory will be recursed regardless of these filters, however
-
 
1262
#                               the filter will be applied when it comes time to chmod the dir 
-
 
1263
#
-
 
1264
#------------------------------------------------------------------------------
-
 
1265
sub SetPermissions
-
 
1266
{
-
 
1267
    my ( $path, $filePerms, $dirPerms, $someDone );
-
 
1268
    my ( $rootOnly, $skipRoot ) = ( 0, 0 );
-
 
1269
    
-
 
1270
    my $search =  JatsLocateFiles->new( '--Recurse', '--DirsToo' );
-
 
1271
 
-
 
1272
    foreach ( @_ )
-
 
1273
    {
-
 
1274
        if ( m/^--Perms=(.*)/ ) {
-
 
1275
            $filePerms = $1;
-
 
1276
            $dirPerms = $1;
-
 
1277
 
-
 
1278
        } elsif (m/^--FilePerms=(.*)/ )  {
-
 
1279
            $filePerms = $1;
-
 
1280
 
-
 
1281
        } elsif ( m/^--DirPerms=(.*)/ )  {
-
 
1282
            $dirPerms = $1;
-
 
1283
 
-
 
1284
        }  elsif ( m/^--RootOnly/ ) {
-
 
1285
            $rootOnly = 1;
-
 
1286
 
-
 
1287
        } elsif ( m/^--SkipRoot/ )  {
-
 
1288
            $skipRoot = 1;
-
 
1289
 
-
 
1290
        } elsif ( m/^--Filter/ && $search->option( $_ ) ) {
-
 
1291
            Verbose2 ("Search Option: $_" );
-
 
1292
 
-
 
1293
        } elsif ( m/^--Recurse|--NoRecurse/ && $search->option( $_ ) ) {
-
 
1294
            Verbose2 ("Search Option: $_" );
-
 
1295
 
-
 
1296
        } elsif (m/^--/ ) {
-
 
1297
            Error ("SetPermissions: Unknown option: $_");
-
 
1298
 
-
 
1299
        } else  {
-
 
1300
            Error("SetPermissions 'path' already set", "Path: $_") if ( $path );
-
 
1301
            $path = $_;
-
 
1302
        }
-
 
1303
    }
-
 
1304
 
-
 
1305
    #
-
 
1306
    #   Sanity test
-
 
1307
    #
-
 
1308
    Error("SetPermissions called with out a 'path' parameter") if ( !defined($path) );
-
 
1309
    Error("SetPermissions called with out any Permissions specified") if ( !defined($filePerms) && !defined($dirPerms) );
-
 
1310
    Error("SetPermissions: Options --RootOnly & --SkipRoot are mutually exclusive" ) if ( $rootOnly && $skipRoot );
-
 
1311
 
-
 
1312
 
-
 
1313
    #   Convert the target directory name into a physical path
-
 
1314
    #   User specifies '/' as the root of the image
-
 
1315
    #   User specifies 'name' as relateve to the root of the image
-
 
1316
    #
-
 
1317
    my $topDir = $DebianWorkDir . '/' . $path;
-
 
1318
    $topDir =~ s~/+$~~;
-
 
1319
 
-
 
1320
    Verbose("SetPermissions: Called with options " . join(", ", @_));
-
 
1321
 
-
 
1322
    #
-
 
1323
    #   Only set perms on the root directory
-
 
1324
    #       This is a trivial operation
-
 
1325
    #
-
 
1326
    if ( $rootOnly )
-
 
1327
    {
-
 
1328
        $someDone += chmodItem( $topDir, $filePerms, $dirPerms );
-
 
1329
    }
-
 
1330
    else
-
 
1331
    {
-
 
1332
        #
-
 
1333
        #   Create a list of files/dirs to process
-
 
1334
        #
-
 
1335
        my @elements = $search->search( $topDir );
-
 
1336
 
-
 
1337
        foreach my $dirEntry ( @elements )
-
 
1338
        {
-
 
1339
            my $fullPath = "$topDir/$dirEntry";
-
 
1340
 
-
 
1341
            # A dir and we dont have dirperms, so skip
-
 
1342
            if ( -d $fullPath && !defined($dirPerms) )
-
 
1343
            {
-
 
1344
                Verbose2("SetPermissions: Skipping dir $fullPath as we have no dir permissions");
-
 
1345
                next;
-
 
1346
            }
-
 
1347
 
-
 
1348
            # A file and we dont have fileperms, so skip
-
 
1349
            if ( -f $fullPath && !defined($filePerms) )
-
 
1350
            {
-
 
1351
                Verbose2("SetPermissions: Skipping file $fullPath as we have no file permissions");
-
 
1352
                next;
-
 
1353
            }
-
 
1354
 
-
 
1355
            # a file or a dir and have the right permissions and we are not recursing
-
 
1356
            if ( -f $fullPath || -d $fullPath )
-
 
1357
            {
-
 
1358
                $someDone += chmodItem( $fullPath, $filePerms, $dirPerms );
-
 
1359
            }
-
 
1360
            else
-
 
1361
            {
-
 
1362
                Warning("SetPermissions: Skipping $fullPath as its not a file or directory");
-
 
1363
            }
-
 
1364
        }
-
 
1365
 
-
 
1366
        #
-
 
1367
        #   Process the topDir
-
 
1368
        #   May not be modified if --SkipRoot has been requested
-
 
1369
        #
-
 
1370
        if ( !$skipRoot && -e $topDir )
-
 
1371
        {
-
 
1372
            $someDone += chmodItem( $topDir, $filePerms, $dirPerms );
-
 
1373
        }
-
 
1374
    }
-
 
1375
 
-
 
1376
    #   Final warning
-
 
1377
    #
-
 
1378
    Warning ("SetPermissions: No files located", "Args: @_") unless ( $someDone );
-
 
1379
}
-
 
1380
 
-
 
1381
#-------------------------------------------------------------------------------
-
 
1382
# Function        : chmodItem 
-
 
1383
#
-
 
1384
# Description     : Internal
-
 
1385
#                   chmod a file or a folder
-
 
1386
#
-
 
1387
# Inputs          : item                        - Item to mod
-
 
1388
#                   filePerms                   - File perms
-
 
1389
#                   dirPerms                    - dire perms
-
 
1390
#
-
 
1391
# Returns         : 1   - Item modified
-
 
1392
#                   0   - Item not modified
-
 
1393
#
-
 
1394
sub chmodItem
-
 
1395
{
-
 
1396
    my ($item, $filePerms, $dirPerms) = @_;
-
 
1397
 
-
 
1398
    if ( -d $item && defined $dirPerms)
-
 
1399
    {
-
 
1400
        Verbose("SetPermissions: $dirPerms : $item");
-
 
1401
        System ('chmod', $dirPerms, $item );
-
 
1402
        return 1;
-
 
1403
    }
-
 
1404
 
-
 
1405
    if ( -f $item  && defined $filePerms)
-
 
1406
    {
-
 
1407
        Verbose("SetPermissions: $filePerms : $item");
-
 
1408
        System ('chmod', $filePerms, $item );
-
 
1409
        return 1;
-
 
1410
    }
-
 
1411
 
-
 
1412
    return 0;
-
 
1413
}
-
 
1414
 
-
 
1415
 
-
 
1416
#-------------------------------------------------------------------------------
1220
# Function        : CreateDir
1417
# Function        : CreateDir
1221
#
1418
#
1222
# Description     : Create a directory within the target workspace
1419
# Description     : Create a directory within the target workspace
1223
#
1420
#
1224
# Inputs          : $path           - Name of the target directory
1421
# Inputs          : $path           - Name of the target directory