📄 filesystem.pm
字号:
chmod $dirs{$dir}, $dir || die $!; } } _create_files(%files); if ($params->{index_html}) { _create_files(%{$fs->{index_html}}); } elsif (-e 'index.html') { my $templatedir = bz_locations()->{'templatedir'}; print <<EOT;*** It appears that you still have an old index.html hanging around. Either the contents of this file should be moved into a template and placed in the '$templatedir/en/custom' directory, or you should delete the file.EOT } # Delete old files that no longer need to exist # 2001-04-29 jake@bugzilla.org - Remove oldemailtech # http://bugzilla.mozilla.org/show_bugs.cgi?id=71552 if (-d 'shadow') { print "Removing shadow directory...\n"; rmtree("shadow"); } if (-e "$datadir/versioncache") { print "Removing versioncache...\n"; unlink "$datadir/versioncache"; }}sub create_htaccess { _create_files(%{FILESYSTEM()->{htaccess}}); # Repair old .htaccess files my $htaccess = new IO::File('.htaccess', 'r') || die ".htaccess: $!"; my $old_data; { local $/; $old_data = <$htaccess>; } $htaccess->close; my $repaired = 0; if ($old_data =~ s/\|localconfig\|/\|.*localconfig.*\|/) { $repaired = 1; } if ($old_data !~ /\(\.\*\\\.pm\|/) { $old_data =~ s/\(/(.*\\.pm\|/; $repaired = 1; } if ($repaired) { print "Repairing .htaccess...\n"; $htaccess = new IO::File('.htaccess', 'w') || die $!; print $htaccess $old_data; $htaccess->close; } my $webdot_dir = bz_locations()->{'webdotdir'}; # The public webdot IP address changed. my $webdot = new IO::File("$webdot_dir/.htaccess", 'r') || die "$webdot_dir/.htaccess: $!"; my $webdot_data; { local $/; $webdot_data = <$webdot>; } $webdot->close; if ($webdot_data =~ /192\.20\.225\.10/) { print "Repairing $webdot_dir/.htaccess...\n"; $webdot_data =~ s/192\.20\.225\.10/192.20.225.0\/24/g; $webdot = new IO::File("$webdot_dir/.htaccess", 'w') || die $!; print $webdot $webdot_data; $webdot->close; }}# A helper for the above functions.sub _create_files { my (%files) = @_; # It's not necessary to sort these, but it does make the # output of checksetup.pl look a bit nicer. foreach my $file (sort keys %files) { unless (-e $file) { print "Creating $file...\n"; my $info = $files{$file}; my $fh = new IO::File($file, O_WRONLY | O_CREAT, $info->{perms}) || die $!; print $fh $info->{contents} if $info->{contents}; $fh->close; } }}# If you ran a REALLY old version of Bugzilla, your chart files are in the# wrong format. This code is a little messy, because it's very old, and# when moving it into this module, I couldn't test it so I left it almost # completely alone.sub _update_old_charts { my ($datadir) = @_; print "Updating old chart storage format...\n"; foreach my $in_file (glob("$datadir/mining/*")) { # Don't try and upgrade image or db files! next if (($in_file =~ /\.gif$/i) || ($in_file =~ /\.png$/i) || ($in_file =~ /\.db$/i) || ($in_file =~ /\.orig$/i)); rename("$in_file", "$in_file.orig") or next; open(IN, "$in_file.orig") or next; open(OUT, '>', $in_file) or next; # Fields in the header my @declared_fields; # Fields we changed to half way through by mistake # This list comes from an old version of collectstats.pl # This part is only for people who ran later versions of 2.11 (devel) my @intermediate_fields = qw(DATE UNCONFIRMED NEW ASSIGNED REOPENED RESOLVED VERIFIED CLOSED); # Fields we actually want (matches the current collectstats.pl) my @out_fields = qw(DATE NEW ASSIGNED REOPENED UNCONFIRMED RESOLVED VERIFIED CLOSED FIXED INVALID WONTFIX LATER REMIND DUPLICATE WORKSFORME MOVED); while (<IN>) { if (/^# fields?: (.*)\s$/) { @declared_fields = map uc, (split /\||\r/, $1); print OUT "# fields: ", join('|', @out_fields), "\n"; } elsif (/^(\d+\|.*)/) { my @data = split(/\||\r/, $1); my %data; if (@data == @declared_fields) { # old format for my $i (0 .. $#declared_fields) { $data{$declared_fields[$i]} = $data[$i]; } } elsif (@data == @intermediate_fields) { # Must have changed over at this point for my $i (0 .. $#intermediate_fields) { $data{$intermediate_fields[$i]} = $data[$i]; } } elsif (@data == @out_fields) { # This line's fine - it has the right number of entries for my $i (0 .. $#out_fields) { $data{$out_fields[$i]} = $data[$i]; } } else { print "Oh dear, input line $. of $in_file had " . scalar(@data) . " fields\nThis was unexpected.", " You may want to check your data files.\n"; } print OUT join('|', map { defined ($data{$_}) ? ($data{$_}) : "" } @out_fields), "\n"; } else { print OUT; } } close(IN); close(OUT); } }sub fix_all_file_permissions { my ($output) = @_; my $ws_group = Bugzilla->localconfig->{'webservergroup'}; my $group_id = _check_web_server_group($ws_group, $output); return if ON_WINDOWS; my $fs = FILESYSTEM(); my %files = %{$fs->{all_files}}; my %dirs = %{$fs->{all_dirs}}; my %recurse_dirs = %{$fs->{recurse_dirs}}; print get_text('install_file_perms_fix') . "\n" if $output; my $owner_id = POSIX::getuid(); $group_id = POSIX::getgid() unless defined $group_id; foreach my $dir (sort keys %dirs) { next unless -d $dir; _fix_perms($dir, $owner_id, $group_id, $dirs{$dir}); } foreach my $dir (sort keys %recurse_dirs) { next unless -d $dir; # Set permissions on the directory itself. my $perms = $recurse_dirs{$dir}; _fix_perms($dir, $owner_id, $group_id, $perms->{dirs}); # Now recurse through the directory and set the correct permissions # on subdirectories and files. find({ no_chdir => 1, wanted => sub { my $name = $File::Find::name; if (-d $name) { _fix_perms($name, $owner_id, $group_id, $perms->{dirs}); } else { _fix_perms($name, $owner_id, $group_id, $perms->{files}); } }}, $dir); } foreach my $file (sort keys %files) { # %files supports globs foreach my $filename (glob $file) { # Don't touch directories. next if -d $filename || !-e $filename; _fix_perms($filename, $owner_id, $group_id, $files{$file}->{perms}); } } _fix_cvs_dirs($owner_id, '.');}# A helper for fix_all_file_permissionssub _fix_cvs_dirs { my ($owner_id, $dir) = @_; my $owner_gid = POSIX::getgid(); find({ no_chdir => 1, wanted => sub { my $name = $File::Find::name; if ($File::Find::dir =~ /\/CVS/ || $_ eq '.cvsignore' || (-d $name && $_ eq 'CVS')) { _fix_perms($name, $owner_id, $owner_gid, 0700); } }}, $dir);}sub _fix_perms { my ($name, $owner, $group, $perms) = @_; #printf ("Changing $name to %o\n", $perms); chown $owner, $group, $name || warn "Failed to change ownership of $name: $!"; chmod $perms, $name || warn "Failed to change permissions of $name: $!";}sub _check_web_server_group { my ($group, $output) = @_; my $filename = bz_locations()->{'localconfig'}; my $group_id; # If we are on Windows, webservergroup does nothing if (ON_WINDOWS && $group && $output) { print "\n\n" . get_text('install_webservergroup_windows') . "\n\n"; } # If we're not on Windows, make sure that webservergroup isn't # empty. elsif (!ON_WINDOWS && !$group && $output) { print "\n\n" . get_text('install_webservergroup_empty') . "\n\n"; } # If we're not on Windows, make sure we are actually a member of # the webservergroup. elsif (!ON_WINDOWS && $group) { $group_id = getgrnam($group); ThrowCodeError('invalid_webservergroup', { group => $group }) unless defined $group_id; # If on unix, see if we need to print a warning about a webservergroup # that we can't chgrp to if ($output && $< != 0 && !grep($_ eq $group_id, split(" ", $)))) { print "\n\n" . get_text('install_webservergroup_not_in') . "\n\n"; } } return $group_id;}1;__END__=head1 NAMEBugzilla::Install::Filesystem - Fix up the filesystem during installation.=head1 DESCRIPTIONThis module is used primarily by L<checksetup.pl> to modify the filesystem during installation, including creating the data/ directory.=head1 SUBROUTINES=over=item C<update_filesystem({ index_html => 0 })>Description: Creates all the directories and files that Bugzilla needs to function but doesn't ship with. Also does any updates to these files as necessary during an upgrade.Params: C<index_html> - Whether or not we should create the F<index.html> file.Returns: nothing=item C<create_htaccess()>Description: Creates all of the .htaccess files for Apache, in the various Bugzilla directories. Also updates the .htaccess files if they need updating.Params: noneReturns: nothing=item C<fix_all_file_permissions($output)>Description: Sets all the file permissions on all of Bugzilla's files to what they should be. Note that permissions are different depending on whether or not C<$webservergroup> is set in F<localconfig>.Params: C<$output> - C<true> if you want this function to print out information about what it's doing.Returns: nothing=back
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -