Subversion Repositories DevTools

Rev

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

Rev 1591 Rev 1592
Line 39... Line 39...
39
use DeployUtils::RmPkgInfo;
39
use DeployUtils::RmPkgInfo;
40
use BuildConfig;
40
use BuildConfig;
41
use Exporter();
41
use Exporter();
42
 
42
 
43
use ArrayHashUtils;
43
use ArrayHashUtils;
-
 
44
use JatsEnv;
44
use JatsError;
45
use JatsError;
45
use JatsSystem;
46
use JatsSystem;
46
 
47
 
47
#
48
#
48
#   The LWP is a part of the Active State Perl, but not the solaris perl
49
#   The LWP is a part of the Active State Perl, but not the solaris perl
Line 114... Line 115...
114
                    &updatePrototypeFileItemClass
115
                    &updatePrototypeFileItemClass
115
                    &useReplaceClass
116
                    &useReplaceClass
116
                    &setReplaceClassFiles
117
                    &setReplaceClassFiles
117
                    &createPkginfoFile
118
                    &createPkginfoFile
118
                    &updatePrototypeFileItemOwner
119
                    &updatePrototypeFileItemOwner
-
 
120
                    &setPermissions
119
                    &chmod
121
                    &chmod
120
                    &chmodRecursive
122
                    &chmodRecursive
121
                    &chmodDir
123
                    &chmodDir
122
                    &chmodFile
124
                    &chmodFile
123
                    &createSymbolicLink
125
                    &createSymbolicLink
Line 1220... Line 1222...
1220
    #   Creating a list allows:
1222
    #   Creating a list allows:
1221
    #       Simplified coding
1223
    #       Simplified coding
1222
    #       Flattening and testing of the flattening
1224
    #       Flattening and testing of the flattening
1223
    #
1225
    #
1224
    my @elements = $search->search( $src_base_dir);
1226
    my @elements = $search->search( $src_base_dir);
-
 
1227
    Warning("installAllDpkgArchivePkgFiles2: No files found") unless ( @elements );
1225
 
1228
 
1226
    #
1229
    #
1227
    #   Perform the file copy
1230
    #   Perform the file copy
1228
    #   This copy will NOT create empty directories, but it will create needed
1231
    #   This copy will NOT create empty directories, but it will create needed
1229
    #   directories on the fly.
1232
    #   directories on the fly.
Line 5609... Line 5612...
5609
 
5612
 
5610
}
5613
}
5611
 
5614
 
5612
 
5615
 
5613
#------------------------------------------------------------------------------
5616
#------------------------------------------------------------------------------
5614
sub chmod
5617
sub setPermissions
-
 
5618
#   Called to set permissions of files/dirs in a directory structure.
-
 
5619
#       With no options sets DirTag and all files/dirs in it to perms
5615
#
5620
#   
5616
# Description:
5621
#   Parameters:  
5617
#       This sub-routine is used to change the ownership of a file or
5622
#               DirTag:  The directory tag to start setting permissions on
-
 
5623
#       
-
 
5624
#   Required Options:
5618
#       directory structure.
5625
#       One or both of
-
 
5626
#               --FilePerms=    Sets the permissions of files to this permission.
-
 
5627
#                               If not supplied then no files have their permissions changed
-
 
5628
#               --DirPerms=     Sets the permissions of directories to this permission
-
 
5629
#                               If not supplied then no directories have their permissions changed
-
 
5630
#       OR
-
 
5631
#               --Perms=        Sets the permissions of both files and directories to this permissions
-
 
5632
#                               Equivalent to supplying both --FilePerms=X && --DirPerms=X
-
 
5633
#               
-
 
5634
#   Options:
-
 
5635
#               --Recurse       Recurse the directory tree.  Does a deptth first recurse so that all 
-
 
5636
#                               dir entries are processed before the dir itself
-
 
5637
#               --NoRecurse     Dont recurse, default
-
 
5638
#               --DirTagOnly    Only sets the permissions on the DirTag directory, 
-
 
5639
#                               all other options ignored
-
 
5640
#               --SkipDirTag    Does not set permissions on the DirTag Directory, 
-
 
5641
#                               obviously mutually exlusive with --DirTagOnly
-
 
5642
#               --FilterIn=     Apply permissions to files/directories that matches this value.
-
 
5643
#               --FilterInRE=   Perl RE's can be used (Not Shell wildcards) and this option
-
 
5644
#                               can be supplied mulitple times
-
 
5645
#               --FilterOut=    Dont apply permissions to any files/directories matching this value
-
 
5646
#               --FilterOutRE=  Perl RE's can be used (Not Shell wildcards) and this option
-
 
5647
#                               can be supplied mulitple times
-
 
5648
#               
-
 
5649
#                               FilterIn is applied before FilterOut.  If Recurse is specified 
-
 
5650
#                               the directory will be recursed regardless of these filters, however
-
 
5651
#                               the filter will be applied when it comes time to chmod the dir 
5619
#
5652
#
5620
#------------------------------------------------------------------------------
5653
#------------------------------------------------------------------------------
5621
{
5654
{
5622
    # correct number of parameters?
5655
    my ( $dirTag, $filePerms, $dirPerms );
-
 
5656
    my ( $dirTagOnly, $skipDirTag ) = ( 0, 0 );
-
 
5657
    
-
 
5658
    my $search =  LocateFiles->new( recurse => 0, dirs_too =>1 );
-
 
5659
 
5623
    if ( ($#_+1) != 3 )
5660
    foreach ( @_ )
5624
    {
5661
    {
5625
        Error("Incorrect number of params passed to " .
5662
        if ( m/^--Perms=(.*)/ ) {
5626
                  "chmod() function. Check deploy config.");
5663
            $filePerms = $1;
5627
    }
5664
            $dirPerms = $1;
5628
 
5665
 
-
 
5666
        } elsif ( m/^--FilePerms=(.*)/ )  {
-
 
5667
            $filePerms = $1;
5629
 
5668
 
-
 
5669
        } elsif ( m/^--DirPerms=(.*)/ )  {
-
 
5670
            $dirPerms = $1;
-
 
5671
 
-
 
5672
        } elsif ( m/^--Recurse/ ) {
-
 
5673
            $search->recurse(1);
-
 
5674
        }
-
 
5675
        elsif ( m/^--NoRecurse/ ) {
-
 
5676
            $search->recurse(0);
-
 
5677
 
-
 
5678
        }  elsif ( m/^--DirTagOnly/ ) {
-
 
5679
            $dirTagOnly = 1;
-
 
5680
 
-
 
5681
        } elsif ( m/^--SkipDirTag/ )  {
-
 
5682
            $skipDirTag = 1;
-
 
5683
 
-
 
5684
        }  elsif ( m/^--FilterInRE=(.*)/ ) {
-
 
5685
            $search->filter_in_re($1);
-
 
5686
 
-
 
5687
        } elsif ( m/^--FilterIn=(.*)/ ) {
5630
    # lets setup the passed values.
5688
            $search->filter_in($1);
-
 
5689
 
-
 
5690
        }  elsif ( m/^--FilterOutRE=(.*)/ ) {
5631
    my ($m_sDirTag, $m_sfile, $m_ownPerms) = @_;
5691
            $search->filter_out_re($1);
5632
 
5692
 
-
 
5693
        }  elsif ( m/^--FilterOut=(.*)/ ) {
-
 
5694
            $search->filter_out($1);
-
 
5695
            
-
 
5696
        } else  {
-
 
5697
            Error("SetPermissions DirTag already set") if ( $dirTag );
-
 
5698
            $dirTag = $_;
-
 
5699
        }
-
 
5700
    }
5633
 
5701
 
-
 
5702
    Error("SetPermissions called with out DirTag parameter") if ( !defined($dirTag) );
-
 
5703
    Error("SetPermissions called with out any Permission options") if ( !defined($filePerms) && !defined($dirPerms) );
-
 
5704
    Error("SetPermissions: Options --DirTagOnly & --SkipDirTag are mutually exclusive" ) if ( $dirTagOnly && $skipDirTag );
-
 
5705
 
-
 
5706
    #
5634
    # lets just check to see if the perms are in correct format.
5707
    # lets just check to see if the perms are in correct format.
5635
    #
5708
    #
5636
    if ( "$m_ownPerms" !~ m/^[0-9][0-9][0-9][0-9]$/ )
5709
    if ( (defined($filePerms) && $filePerms !~ m/^\d{4}$/) || (defined($dirPerms) && $dirPerms !~ m/^\d{4}$/) )
5637
    {
5710
    {
5638
        Error("chmod() does not support [$m_ownPerms] permission, use format 0755 etc.");
5711
        Error("setPermissions called with invalid permissions format");
5639
        return 1;
-
 
5640
    }
5712
    }
5641
 
5713
 
5642
    # lets get the absolute src dir value
5714
    #   Convert the symbolic target directory name into a real path
5643
    my ($m_sDirAbsoluteValue) = getTargetDstDirValue($m_sDirTag, "A");
5715
    my ($topDir) = getTargetDstDirValue($dirTag, "A");
5644
 
5716
 
-
 
5717
    #
-
 
5718
    #   Only set perms on the root directory
-
 
5719
    #   This is a trivial operation
5645
    my($item);
5720
    #
5646
    if ( "x$m_sfile" eq "x" )
5721
    if ( $dirTagOnly )
5647
    {
5722
    {
-
 
5723
        Error("SetPermissions:  --DirPerms or --Perms not supplied for setting perms with --DirTagOnly") 
-
 
5724
            if ( ! defined($dirPerms) );
-
 
5725
        Information("SetPermissions: Setting permissions on top level dir only [$topDir] to " . $dirPerms);
5648
        $item = "$m_sDirAbsoluteValue";
5726
        chmodFile($topDir, $dirPerms);
-
 
5727
        return;
5649
    }
5728
    }
-
 
5729
 
-
 
5730
    Information("SetPermissions: Called with options " . join(", ", @_));
-
 
5731
 
-
 
5732
 
-
 
5733
    #
-
 
5734
    #   Create a list of files/dirs to process
5650
    else
5735
    #
-
 
5736
    my @elements = $search->search( $topDir );
-
 
5737
    Warning ("setPermissions: No files located") unless ( @elements );
-
 
5738
 
-
 
5739
    foreach my $dirEntry ( @elements )
5651
    {
5740
    {
5652
        $item = "$m_sDirAbsoluteValue/$m_sfile";
5741
        my $fullPath = "$topDir/$dirEntry";
-
 
5742
 
-
 
5743
        # A dir and we dont have dirperms, so skip
-
 
5744
        if ( -d $fullPath && !defined($dirPerms) )
-
 
5745
        {
-
 
5746
            Debug2("SetPermissions: Skipping dir $fullPath as we have no dir permissions");
-
 
5747
            next;
-
 
5748
        }
-
 
5749
 
-
 
5750
        # A file and we dont have fileperms, so skip
-
 
5751
        if ( -f $fullPath && !defined($filePerms) )
-
 
5752
        {
-
 
5753
            Debug2("SetPermissions: Skipping file $fullPath as we have no file permissions");
-
 
5754
            next;
-
 
5755
        }
-
 
5756
 
-
 
5757
        # a file or a dir and have the right permissions and we are not recursing
-
 
5758
        if ( -f $fullPath || -d $fullPath )
-
 
5759
        {
-
 
5760
            chmodFile($fullPath, ( -f $fullPath ) ? $filePerms : $dirPerms);
-
 
5761
        }
-
 
5762
        else
-
 
5763
        {
-
 
5764
            Warning("SetPermissions: Skipping $fullPath as its not a file or directory");
-
 
5765
        }
5653
    }
5766
    }
5654
 
5767
 
-
 
5768
 
-
 
5769
    #
5655
    # check to see if item exists
5770
    #   Process the topDir
-
 
5771
    #   May not be modified if --SkipDirTag has been requested
5656
    #
5772
    #
5657
    if ( ! -f "$item" && 
5773
    if ( !$skipDirTag && defined($dirPerms) )
5658
         ! -d "$item" )
-
 
5659
    {
5774
    {
5660
        Error("Failed to find item [$item]. Check deploy config."); 
5775
        chmodFile($topDir, $dirPerms);
5661
    }
5776
    }
-
 
5777
 
-
 
5778
}   # setPermissions
-
 
5779
 
-
 
5780
 
-
 
5781
#------------------------------------------------------------------------------
-
 
5782
sub chmod
-
 
5783
#
-
 
5784
# Description:
-
 
5785
#       This sub-routine is used to change the ownership of a file or
-
 
5786
#       directory structure.
-
 
5787
#
-
 
5788
#------------------------------------------------------------------------------
-
 
5789
{
-
 
5790
    # correct number of parameters?
5662
    Verbose("chmod: Changing permisions of file [$m_sfile] in dirtag [$m_sDirTag] to [$m_ownPerms]");
5791
    Error("Incorrect number of params passed to chmod() function. Check deploy config.") if ( ($#_+1) != 3 );
-
 
5792
 
-
 
5793
    # lets setup the passed values.
5663
    chmodFile("$item", $m_ownPerms);
5794
    my ($m_sDirTag, $m_sfile, $m_ownPerms) = @_;
-
 
5795
 
-
 
5796
    Warning("chmod has been deprecated by and now calls setPermissions, see deploylib.pm");
-
 
5797
 
-
 
5798
    # call setPermissions, if no File then do DirTagOnly, otherwise set FilterIn=File
-
 
5799
    setPermissions($m_sDirTag, "--NoRecurse", "--Perms=$m_ownPerms", 
-
 
5800
                    ($m_sfile eq "") ? "--DirTagOnly" : "--FilterIn=$m_sfile" );
5664
 
5801
 
5665
    return 1;
5802
    return 1;
5666
}
5803
}
5667
 
5804
 
5668
 
5805
 
Line 5674... Line 5811...
5674
#       the target packgae.
5811
#       the target packgae.
5675
#
5812
#
5676
#------------------------------------------------------------------------------
5813
#------------------------------------------------------------------------------
5677
{
5814
{
5678
    # correct number of parameters?
5815
    # correct number of parameters?
5679
    if ( ($#_+1) != 2 )
-
 
5680
    {
-
 
5681
        Error("Incorrect number of params passed to " .
-
 
5682
                  "chmodRecursive() function. Check deploy config.");
5816
    Error("Incorrect number of params passed to chmodRecursive() function. Check deploy config.") if ( ($#_+1) != 2 );
5683
    }
-
 
5684
 
5817
 
5685
    # lets setup the passed values.
5818
    # lets setup the passed values.
5686
    my ($m_sDirTag, $m_ownPerms) = @_;
5819
    my ($m_sDirTag, $m_ownPerms) = @_;
5687
 
5820
 
5688
    # lets just check to see if the perms are in correct format.
-
 
5689
    #
-
 
5690
    if ( "$m_ownPerms" !~ m/^[0-9][0-9][0-9][0-9]$/ )
-
 
5691
    {
-
 
5692
        Error("chmod() does not support [$m_ownPerms] permission, use format 0755 etc.");
5821
    Warning("chmodRecursive has been deprecated by and now calls setPermissions, see deploylib.pm");
5693
        return 1;
-
 
5694
    }
-
 
5695
 
-
 
5696
 
-
 
5697
    # lets get the absolute src dir value
-
 
5698
    my ($m_sDirAbsoluteValue) = getTargetDstDirValue($m_sDirTag, "A");
-
 
5699
 
5822
 
5700
 
-
 
5701
    # check to see if item exists
-
 
5702
    #
-
 
5703
    if ( ! -f "$m_sDirAbsoluteValue" &&
-
 
5704
         ! -d "$m_sDirAbsoluteValue" )
-
 
5705
    {
-
 
5706
        Error("Failed to find item [$m_sDirAbsoluteValue]. " .
-
 
5707
                  "Check deploy config."); 
-
 
5708
    }
-
 
5709
 
-
 
5710
 
-
 
5711
    # if its a not a dir
-
 
5712
    #
-
 
5713
    if ( ! -d "$m_sDirAbsoluteValue" && -f "$m_sDirAbsoluteValue" )
-
 
5714
    {
-
 
5715
        Warning("chmodRecursive: This should not happen as dirtag [$m_sDirTag] is a file, changings perms to [$m_ownPerms] anyway");
-
 
5716
        chmodFile("$m_sDirAbsoluteValue", $m_ownPerms);
-
 
5717
    }
-
 
5718
    else
-
 
5719
    {
-
 
5720
        # it must be a dir
-
 
5721
        Verbose("chmodRecursive: Recursively setting perms on dirtag [$m_sDirTag] to [$m_ownPerms]");
5823
    # call setPermissions, if no File then do DirTagOnly, otherwise set FilterIn=File
5722
        chmodDir("$m_sDirAbsoluteValue", $m_ownPerms);
5824
    setPermissions($m_sDirTag, "--Recurse", "--Perms=$m_ownPerms");
5723
    }
-
 
5724
 
5825
 
5725
    return 1;
5826
    return 1;
5726
}
5827
}
5727
 
5828
 
5728
 
5829
 
Line 5738... Line 5839...
5738
#       finds a dir it recurses into that dir chmod'ing it as well.
5839
#       finds a dir it recurses into that dir chmod'ing it as well.
5739
#
5840
#
5740
#------------------------------------------------------------------------------
5841
#------------------------------------------------------------------------------
5741
{
5842
{
5742
    # correct number of parameters?
5843
    # correct number of parameters?
5743
    if ( ($#_+1) != 2 )
-
 
5744
    {
-
 
5745
        Error("Incorrect number of params passed to " .
5844
    Error("Incorrect number of params passed to chmodDir() function.") if ( ($#_+1) != 2 );
5746
                  "chmodDir() function.");
-
 
5747
    }
-
 
5748
 
5845
 
5749
    my ($startingPoint, $perms) = @_;
5846
    my ($startingPoint, $perms) = @_;
5750
 
5847
 
-
 
5848
    Warning("chmodDir has been deprecated by setPermissions, see deploylib.pm");
-
 
5849
 
5751
    Verbose("chmodDir: Recursively setting permsision of [$startingPoint] to [$perms]");
5850
    Verbose("chmodDir: Recursively setting permsision of [$startingPoint] to [$perms]");
5752
 
5851
 
5753
    local *DIR;
5852
    local *DIR;
5754
    opendir(DIR, $startingPoint) or
-
 
5755
        Error("can't opendir $startingPoint: $!");
5853
    opendir(DIR, $startingPoint) or Error("can't opendir $startingPoint: $!");
5756
 
5854
 
5757
    my ($item);
5855
    my ($item);
5758
    while (defined($item = readdir(DIR)))
5856
    while (defined($item = readdir(DIR)))
5759
    {
5857
    {
5760
        if ( "$item" !~ /^\.$/  &&
-
 
5761
             "$item" !~ /^\.\.$/ )
5858
        if ( "$item" !~ /^\.$/  && "$item" !~ /^\.\.$/ )
5762
        {
5859
        {
5763
            if ( -d "$startingPoint/$item" )
5860
            if ( -d "$startingPoint/$item" )
5764
            {
5861
            {
5765
                chmodDir("$startingPoint/$item", $perms);
5862
                chmodDir("$startingPoint/$item", $perms);
5766
            }
5863
            }
Line 5790... Line 5887...
5790
#
5887
#
5791
#------------------------------------------------------------------------------
5888
#------------------------------------------------------------------------------
5792
{
5889
{
5793
    my ($item, $perms) = @_;
5890
    my ($item, $perms) = @_;
5794
 
5891
 
5795
    my ($cmd) = "CORE::chmod $perms, $item";
-
 
5796
    my ($noItems) = CORE::chmod oct($perms), $item;
5892
    my ($noItems) = CORE::chmod oct($perms), $item;
5797
    if ( $noItems == 0 )
5893
    if ( $noItems == 0 )
5798
    {
5894
    {
5799
        Error("Failed to complete command [$cmd], retVal=[$noItems]");
5895
        Error("ERROR: Failed to chmod $item=$perms, retVal=[$noItems]");
5800
    }
5896
    }
5801
    else
5897
    else
5802
    {
5898
    {
5803
        Debug("Executed command: [$cmd]");
5899
        Debug("Successfully chmod $item=$perms");
5804
    }
5900
    }
5805
 
5901
 
5806
    return 1;
5902
    return 1;
5807
}
5903
}
5808
 
5904
 
Line 7716... Line 7812...
7716
    $self->{recurse}  = 0;
7812
    $self->{recurse}  = 0;
7717
    $self->{exclude}  = [];
7813
    $self->{exclude}  = [];
7718
    $self->{include}  = [];
7814
    $self->{include}  = [];
7719
    $self->{base_dir} = undef;
7815
    $self->{base_dir} = undef;
7720
    $self->{results}  = [];
7816
    $self->{results}  = [];
-
 
7817
    $self->{dirs_too} = 0;
7721
    bless ($self, $class);
7818
    bless ($self, $class);
7722
 
7819
 
7723
    #
7820
    #
7724
    #   Process user arguments
7821
    #   Process user arguments
7725
    #   These are are a hash
7822
    #   These are are a hash
Line 7782... Line 7879...
7782
    my $self = shift;
7879
    my $self = shift;
7783
    if (@_) { push @{$self->{exclude}}, shift }
7880
    if (@_) { push @{$self->{exclude}}, shift }
7784
    return $self->{exclude};
7881
    return $self->{exclude};
7785
}
7882
}
7786
 
7883
 
-
 
7884
sub dirs_too
-
 
7885
{
-
 
7886
    my $self = shift;
-
 
7887
    if (@_) { $self->{dirs_too} = shift }
-
 
7888
    return $self->{dirs_too};
-
 
7889
}
-
 
7890
 
7787
sub base_dir
7891
sub base_dir
7788
{
7892
{
7789
    my $self = shift;
7893
    my $self = shift;
7790
    if (@_) { $self->{base_dir} = shift }
7894
    if (@_) { $self->{base_dir} = shift }
7791
    return $self->{base_dir};
7895
    return $self->{base_dir};
Line 7847... Line 7951...
7847
    #
7951
    #
7848
    if ( $self->{recurse} )
7952
    if ( $self->{recurse} )
7849
    {
7953
    {
7850
        sub find_file_wanted
7954
        sub find_file_wanted
7851
        {
7955
        {
7852
            return if ( -d $_ );
7956
            return if ( !$self->{dirs_too} && -d $_ );
7853
            my $file = $File::Find::name;
7957
            my $file = $File::Find::name;
7854
            push @search_list, substr($file, $search_len );
7958
            push @search_list, substr($file, $search_len );
7855
        }
7959
        }
7856
 
7960
 
7857
        #
7961
        #
Line 7872... Line 7976...
7872
        opendir DIR, $self->{base_dir} || die ("Cannot open $self->{base_dir}");
7976
        opendir DIR, $self->{base_dir} || die ("Cannot open $self->{base_dir}");
7873
        foreach ( readdir( DIR ) )
7977
        foreach ( readdir( DIR ) )
7874
        {
7978
        {
7875
            next if /^\Q.\E$/;
7979
            next if /^\Q.\E$/;
7876
            next if /^\Q..\E$/;
7980
            next if /^\Q..\E$/;
7877
            next if ( -d "$self->{base_dir}/$_" );
7981
            next if ( !$self->{dirs_too} && -d "$self->{base_dir}/$_" );
7878
            push @search_list, '/' . $_;
7982
            push @search_list, '/' . $_;
7879
 
7983
 
7880
        }
7984
        }
7881
        closedir DIR;
7985
        closedir DIR;
7882
    }
7986
    }