Commit f2d5af26 authored by Max Kanat-Alexander's avatar Max Kanat-Alexander

Bug 602418: Add "template_cache" to bz_locations(), a way of specifying that

cached templates should be stored somewhere else than the data directory. r=LpSolit, a=mkanat
parent 8cfb548a
...@@ -596,6 +596,7 @@ sub bz_locations { ...@@ -596,6 +596,7 @@ sub bz_locations {
$datadir = "data"; $datadir = "data";
} }
$datadir = "$libpath/$datadir";
# We have to return absolute paths for mod_perl. # We have to return absolute paths for mod_perl.
# That means that if you modify these paths, they must be absolute paths. # That means that if you modify these paths, they must be absolute paths.
return { return {
...@@ -605,10 +606,11 @@ sub bz_locations { ...@@ -605,10 +606,11 @@ sub bz_locations {
# make sure this still points to the CGIs. # make sure this still points to the CGIs.
'cgi_path' => $libpath, 'cgi_path' => $libpath,
'templatedir' => "$libpath/template", 'templatedir' => "$libpath/template",
'template_cache' => "$datadir/template",
'project' => $project, 'project' => $project,
'localconfig' => "$libpath/$localconfig", 'localconfig' => "$libpath/$localconfig",
'datadir' => "$libpath/$datadir", 'datadir' => $datadir,
'attachdir' => "$libpath/$datadir/attachments", 'attachdir' => "$datadir/attachments",
'skinsdir' => "$libpath/skins", 'skinsdir' => "$libpath/skins",
# $webdotdir must be in the web server's tree somewhere. Even if you use a # $webdotdir must be in the web server's tree somewhere. Even if you use a
# local dot, we output images to there. Also, if $webdotdir is # local dot, we output images to there. Also, if $webdotdir is
...@@ -616,7 +618,7 @@ sub bz_locations { ...@@ -616,7 +618,7 @@ sub bz_locations {
# change showdependencygraph.cgi to set image_url to the correct # change showdependencygraph.cgi to set image_url to the correct
# location. # location.
# The script should really generate these graphs directly... # The script should really generate these graphs directly...
'webdotdir' => "$libpath/$datadir/webdot", 'webdotdir' => "$datadir/webdot",
'extensionsdir' => "$libpath/extensions", 'extensionsdir' => "$libpath/extensions",
}; };
} }
......
...@@ -121,6 +121,7 @@ sub FILESYSTEM { ...@@ -121,6 +121,7 @@ sub FILESYSTEM {
my $extlib = bz_locations()->{'ext_libpath'}; my $extlib = bz_locations()->{'ext_libpath'};
my $skinsdir = bz_locations()->{'skinsdir'}; my $skinsdir = bz_locations()->{'skinsdir'};
my $localconfig = bz_locations()->{'localconfig'}; my $localconfig = bz_locations()->{'localconfig'};
my $template_cache = bz_locations()->{'template_cache'};
# We want to set the permissions the same for all localconfig files # We want to set the permissions the same for all localconfig files
# across all PROJECTs, so we do something special with $localconfig, # across all PROJECTs, so we do something special with $localconfig,
...@@ -189,7 +190,7 @@ sub FILESYSTEM { ...@@ -189,7 +190,7 @@ sub FILESYSTEM {
# the webserver. # the webserver.
my %recurse_dirs = ( my %recurse_dirs = (
# Writeable directories # Writeable directories
"$datadir/template" => { files => CGI_READ, $template_cache => { files => CGI_READ,
dirs => DIR_CGI_OVERWRITE }, dirs => DIR_CGI_OVERWRITE },
$attachdir => { files => CGI_WRITE, $attachdir => { files => CGI_WRITE,
dirs => DIR_CGI_WRITE }, dirs => DIR_CGI_WRITE },
......
...@@ -633,7 +633,7 @@ sub create { ...@@ -633,7 +633,7 @@ sub create {
ABSOLUTE => 1, ABSOLUTE => 1,
RELATIVE => $ENV{MOD_PERL} ? 0 : 1, RELATIVE => $ENV{MOD_PERL} ? 0 : 1,
COMPILE_DIR => bz_locations()->{'datadir'} . "/template", COMPILE_DIR => bz_locations()->{'template_cache'},
# Initialize templates (f.e. by loading plugins like Hook). # Initialize templates (f.e. by loading plugins like Hook).
PRE_PROCESS => ["global/initialize.none.tmpl"], PRE_PROCESS => ["global/initialize.none.tmpl"],
...@@ -990,23 +990,27 @@ sub precompile_templates { ...@@ -990,23 +990,27 @@ sub precompile_templates {
my ($output) = @_; my ($output) = @_;
# Remove the compiled templates. # Remove the compiled templates.
my $cache_dir = bz_locations()->{'template_cache'};
my $datadir = bz_locations()->{'datadir'}; my $datadir = bz_locations()->{'datadir'};
if (-e "$datadir/template") { if (-e $cache_dir) {
print install_string('template_removing_dir') . "\n" if $output; print install_string('template_removing_dir') . "\n" if $output;
# This frequently fails if the webserver made the files, because # This frequently fails if the webserver made the files, because
# then the webserver owns the directories. # then the webserver owns the directories.
rmtree("$datadir/template"); rmtree($cache_dir);
# Check that the directory was really removed, and if not, move it # Check that the directory was really removed, and if not, move it
# into data/deleteme/. # into data/deleteme/.
if (-e "$datadir/template") { if (-e $cache_dir) {
my $deleteme = "$datadir/deleteme";
print STDERR "\n\n", print STDERR "\n\n",
install_string('template_removal_failed', install_string('template_removal_failed',
{ datadir => $datadir }), "\n\n"; { deleteme => $deleteme,
mkpath("$datadir/deleteme"); template_cache => $cache_dir }), "\n\n";
mkpath($deleteme);
my $random = generate_random_password(); my $random = generate_random_password();
rename("$datadir/template", "$datadir/deleteme/$random") rename($cache_dir, "$deleteme/$random")
or die "move failed: $!"; or die "move failed: $!";
} }
} }
...@@ -1071,10 +1075,10 @@ sub _do_template_symlink { ...@@ -1071,10 +1075,10 @@ sub _do_template_symlink {
my $abs_root = dirname($abs_path); my $abs_root = dirname($abs_path);
my $dir_name = basename($abs_path); my $dir_name = basename($abs_path);
my $datadir = bz_locations()->{'datadir'}; my $cache_dir = bz_locations()->{'template_cache'};
my $container = "$datadir/template$abs_root"; my $container = "$cache_dir$abs_root";
mkpath($container); mkpath($container);
my $target = "$datadir/template/$dir_name"; my $target = "$cache_dir/$dir_name";
# Check if the directory exists, because if there are no extensions, # Check if the directory exists, because if there are no extensions,
# there won't be an "data/template/extensions" directory to link to. # there won't be an "data/template/extensions" directory to link to.
if (-d $target) { if (-d $target) {
......
...@@ -389,8 +389,8 @@ EOT ...@@ -389,8 +389,8 @@ EOT
EOT EOT
template_precompile => "Precompiling templates...", template_precompile => "Precompiling templates...",
template_removal_failed => <<END, template_removal_failed => <<END,
WARNING: The directory '##datadir##/template' could not be removed. WARNING: The directory '##template_cache##' could not be removed.
It has been moved into '##datadir##/deleteme', which should be It has been moved into '##deleteme##', which should be
deleted manually to conserve disk space. deleted manually to conserve disk space.
END END
template_removing_dir => "Removing existing compiled templates...", template_removing_dir => "Removing existing compiled templates...",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment