[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.45, Mon May 8 20:37:02 2006 UTC revision 1.46, Thu Jun 8 13:42:24 2006 UTC
# Line 2008  Line 2008 
2008      }      }
2009  }  }
2010    
2011    =head3 SetPermissions
2012    
2013    C<< Tracer::SetPermissions($dirName, $group, $mask); >>
2014    
2015    Set the permissions for a directory and all the files and folders inside it.
2016    In addition, the group ownership will be changed to the specified value.
2017    
2018    This method is more vulnerable than most to permission and compatability
2019    problems, so it does internal error recovery.
2020    
2021    =over 4
2022    
2023    =item dirName
2024    
2025    Name of the directory to process.
2026    
2027    =item group
2028    
2029    Name of the group to be assigned.
2030    
2031    =item mask
2032    
2033    Permission mask. Bits that are C<1> in this mask will be ORed into the
2034    permission bits of any file or directory that does not already have them
2035    set to 1.
2036    
2037    =back
2038    
2039    =cut
2040    
2041    sub SetPermissions {
2042        # Get the parameters.
2043        my ($dirName, $group, $mask) = @_;
2044        # Set up for error recovery.
2045        eval {
2046            ChDir($dirName);
2047            # Get the group ID.
2048            my $gid = getgrnam($group);
2049            Trace("Fixing permissions for directory $dirName using group $group($gid).") if T(2);
2050            my $fixCount = 0;
2051            my $lookCount = 0;
2052            # @dirs will be a stack of directories to be processed.
2053            my @dirs = (getcwd());
2054            while (scalar(@dirs) > 0) {
2055                # Get the current directory.
2056                my $dir = pop @dirs;
2057                # Get all its non-hidden members.
2058                my @submems = OpenDir($dir, 1);
2059                for my $submem (@submems) {
2060                    # Get the full name.
2061                    my $thisMem = "$dir/$submem";
2062                    Trace("Checking member $thisMem.") if T(4);
2063                    $lookCount++;
2064                    if ($lookCount % 1000 == 0) {
2065                        Trace("$lookCount members examined. Current is $thisMem.") if T(3);
2066                    }
2067                    # Fix the group.
2068                    chown -1, $gid, $thisMem;
2069                    # Insure this member is not a symlink.
2070                    if (! -l $thisMem) {
2071                        # Get its info.
2072                        my $fileInfo = stat $thisMem;
2073                        # Only proceed if we got the info. Otherwise, it's a hard link
2074                        # and we want to skip it anyway.
2075                        if ($fileInfo) {
2076                            my $fileMode = $fileInfo->mode;
2077                            if (($fileMode & $mask) == 0) {
2078                                # Fix this member.
2079                                $fileMode |= $mask;
2080                                chmod $fileMode, $thisMem;
2081                                $fixCount++;
2082                            }
2083                            # If it's a subdirectory, stack it.
2084                            if (-d $thisMem) {
2085                                push @dirs, $thisMem;
2086                            }
2087                        }
2088                    }
2089                }
2090            }
2091            Trace("$lookCount files and directories processed, $fixCount fixed.") if T(2);
2092        };
2093        # Check for an error.
2094        if ($@) {
2095            Confess("SetPermissions error: $@");
2096        }
2097    }
2098    
2099  1;  1;

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.46

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3