[Bio] / FigKernelPackages / Tracer.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/Tracer.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.47, Thu Jun 8 13:52:23 2006 UTC revision 1.52, Wed Jun 14 01:12:42 2006 UTC
# Line 30  Line 30 
30      use Digest::MD5;      use Digest::MD5;
31      use File::Basename;      use File::Basename;
32      use File::Path;      use File::Path;
33        use File::stat;
34    
35  =head1 Tracing and Debugging Helpers  =head1 Tracing and Debugging Helpers
36    
# Line 2011  Line 2012 
2012    
2013  =head3 SetPermissions  =head3 SetPermissions
2014    
2015  C<< Tracer::SetPermissions($dirName, $group, $mask); >>  C<< Tracer::SetPermissions($dirName, $group, $mask, %otherMasks); >>
2016    
2017  Set the permissions for a directory and all the files and folders inside it.  Set the permissions for a directory and all the files and folders inside it.
2018  In addition, the group ownership will be changed to the specified value.  In addition, the group ownership will be changed to the specified value.
# Line 2035  Line 2036 
2036  permission bits of any file or directory that does not already have them  permission bits of any file or directory that does not already have them
2037  set to 1.  set to 1.
2038    
2039    =item otherMasks
2040    
2041    Map of search patterns to permission masks. If a directory name matches
2042    one of the patterns, that directory and all its members and subdirectories
2043    will be assigned the new pattern. For example, the following would
2044    assign 01664 to most files, but would use 01777 for directories named C<tmp>.
2045    
2046        Tracer::SetPermissions($dirName, 'fig', 01664, '^tmp$' => 01777);
2047    
2048    The list is ordered, so the following would use 0777 for C<tmp1> and
2049    0666 for C<tmp>, C<tmp2>, or C<tmp3>.
2050    
2051        Tracer::SetPermissions($dirName, 'fig', 01664, '^tmp1' => 0777,
2052                                                       '^tmp' => 0666);
2053    
2054    Note that the pattern matches are all case-insensitive, and only directory
2055    names are matched, not file names.
2056    
2057  =back  =back
2058    
2059  =cut  =cut
2060    
2061  sub SetPermissions {  sub SetPermissions {
2062      # Get the parameters.      # Get the parameters.
2063      my ($dirName, $group, $mask) = @_;      my ($dirName, $group, $mask, @otherMasks) = @_;
2064      # Set up for error recovery.      # Set up for error recovery.
2065      eval {      eval {
2066            # Switch to the specified directory.
2067          ChDir($dirName);          ChDir($dirName);
2068          # Get the group ID.          # Get the group ID.
2069          my $gid = getgrnam($group);          my $gid = getgrnam($group);
2070          Trace("Fixing permissions for directory $dirName using group $group($gid).") if T(2);          # Get the mask for tracing.
2071            my $traceMask = sprintf("%04o", $mask) . "($mask)";
2072            Trace("Fixing permissions for directory $dirName using group $group($gid) and mask $traceMask.") if T(2);
2073          my $fixCount = 0;          my $fixCount = 0;
2074          my $lookCount = 0;          my $lookCount = 0;
2075          # @dirs will be a stack of directories to be processed.          # @dirs will be a stack of directories to be processed.
# Line 2055  Line 2077 
2077          while (scalar(@dirs) > 0) {          while (scalar(@dirs) > 0) {
2078              # Get the current directory.              # Get the current directory.
2079              my $dir = pop @dirs;              my $dir = pop @dirs;
2080              # Get all its non-hidden members.              # Check for a match to one of the specified directory names. To do
2081                # that, we need to pull the individual part of the name off of the
2082                # whole path.
2083                my $simpleName = $dir;
2084                if ($dir =~ m!/(.+)$!) {
2085                    $simpleName = $1;
2086                }
2087                # Search for a match.
2088                my $match = 0;
2089                my $i;
2090                for ($i = 0; $i < $#otherMasks && ! $match; $i += 2) {
2091                    my $pattern = $otherMasks[$i];
2092                    if ($simpleName =~ /$pattern/i) {
2093                        $match = 1;
2094                    }
2095                }
2096                # Check for a match. Note we use $i-1 because the loop added 2
2097                # before terminating due to the match.
2098                if ($match && $otherMasks[$i-1] != $mask) {
2099                    # This directory matches one of the incoming patterns, and it's
2100                    # a different mask, so we process it recursively with that mask.
2101                    SetPermissions($dir, $group, $otherMasks[$i-1], @otherMasks);
2102                } else {
2103                    # Here we can process normally. Get all of the non-hidden members.
2104              my @submems = OpenDir($dir, 1);              my @submems = OpenDir($dir, 1);
2105              for my $submem (@submems) {              for my $submem (@submems) {
2106                  # Get the full name.                  # Get the full name.
# Line 2063  Line 2108 
2108                  Trace("Checking member $thisMem.") if T(4);                  Trace("Checking member $thisMem.") if T(4);
2109                  $lookCount++;                  $lookCount++;
2110                  if ($lookCount % 1000 == 0) {                  if ($lookCount % 1000 == 0) {
2111                      Trace("$lookCount members examined. Current is $thisMem.") if T(3);                          Trace("$lookCount members examined. Current is $thisMem. Mask is $traceMask") if T(3);
2112                  }                  }
2113                  # Fix the group.                  # Fix the group.
2114                  chown -1, $gid, $thisMem;                  chown -1, $gid, $thisMem;
# Line 2089  Line 2134 
2134                  }                  }
2135              }              }
2136          }          }
2137            }
2138          Trace("$lookCount files and directories processed, $fixCount fixed.") if T(2);          Trace("$lookCount files and directories processed, $fixCount fixed.") if T(2);
2139      };      };
2140      # Check for an error.      # Check for an error.

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.52

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3