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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3