use File::Find;
use File::Path;
use File::Basename;
+use File::Copy qw(move);
use IO::File;
use POSIX ();
'docs/*/README.docs' => { perms => $owner_readable },
"$datadir/bugzilla-update.xml" => { perms => $ws_writeable },
"$datadir/params" => { perms => $ws_writeable },
- "$datadir/mailer.testfile" => { perms => $ws_writeable },
);
# Directories that we want to set the perms on, but not
# The name of each file, pointing at its default permissions and
# default contents.
- my %create_files = ();
+ my %create_files = (
+ # We create this file so that it always has the right owner
+ # and permissions. Otherwise, the webserver creates it as
+ # owned by itself, which can cause problems if jobqueue.pl
+ # or something else is not running as the webserver or root.
+ "$datadir/mailer.testfile" => { perms => $ws_writeable,
+ contents => '' },
+ );
# Each standard stylesheet has an associated custom stylesheet that
# we create. Also, we create placeholders for standard stylesheets
}
}
+ # Move the testfile if we can't write to it, so that we can re-create
+ # it with the correct permissions below.
+ if (!-w "$datadir/mailer.testfile") {
+ _rename_file("$datadir/mailer.testfile",
+ "$datadir/mailer.testfile.old");
+ }
+
_create_files(%files);
if ($params->{index_html}) {
_create_files(%{$fs->{index_html}});
}
}
+sub _rename_file {
+ my ($from, $to) = @_;
+ print "Renaming $from to $to...\n";
+ if (-e $to) {
+ warn "$to already exists, not moving\n";
+ }
+ else {
+ move($from, $to) or warn $!;
+ }
+}
+
# A helper for the above functions.
sub _create_files {
my (%files) = @_;