I missed the directories created by File::Temp::tempfile
I added a part for giving those dirs the right mode as well, whithout
using any extra modules or functions. Here is a patch of my version as
it now stands. But I would suggest make the default modes configurable.
I order to have any use of this, the umask of the involved users should
be 0002 rather than 0022.
To reiterate:
If a program using TT ir run by user1, the compiled tamplates will be
crated owned by that user and with no permissions for anyone else to
change them. Then user2 runs the same program, it will run fine until it
has to update a template, and then fail because of insuficiient permission.
This change will give all users in the same group access to the template
cache.
--- Document.pm.orig 2005-09-11 16:45:30.000000000 +0200
+++ Document.pm 2005-09-11 18:19:18.000000000 +0200
@@ -285,26 +285,46 @@
sub write_perl_file {
my ($class, $file, $content) = @_;
my ($fh, $tmpfile);
return $class->error("invalid filename: $file")
unless $file =~ /^(.+)$/s;
+ my $mode = 0660;
+ my $dirmode = 02770;
+
eval {
require File::Temp;
require File::Basename;
+
+ if ( $mode ) {
+ my $parent = File::Basename::dirname($file);
+ my @dirs = ();
+ while ( not -e $parent ) {
+ unshift @dirs, $parent;
+ $parent = File::Basename::dirname($parent);
+ }
+ foreach my $dir ( @dirs ) {
+ mkdir $dir or return $class->error($!);
+ chmod $dirmode, $dir or return $class->error($!);
+ }
+ }
+
($fh, $tmpfile) = File::Temp::tempfile(
DIR => File::Basename::dirname($file)
);
my $perlcode = $class->as_perl($content) || die $!;
if ($UNICODE && is_utf8($perlcode)) {
$perlcode = "use utf8;\n\n$perlcode";
binmode $fh, ":utf8";
}
print $fh $perlcode;
close($fh);
};
return $class->error($@) if $@;
+ if ( $mode ) {
+ chmod $mode, $tmpfile or return $class->error($!);
+ }
return rename($tmpfile, $file)
|| $class->error($!);
}
--
/ Jonas - http://jonas.liljegren.org/myself/
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates