From 407c6763f8f7e3838bd5e17c3bb5b039bdbfc92f Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Thu, 27 Sep 2018 18:24:00 -0700 Subject: Arrange for Tempfiles to be safely written in-dir The default File::Temp DIR is not necessarily the same filesystem as the destination, which makes atomic linking impossible. --- libpiny/lib/Piny/Repo.pm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'libpiny') diff --git a/libpiny/lib/Piny/Repo.pm b/libpiny/lib/Piny/Repo.pm index a319255..d2dfc19 100644 --- a/libpiny/lib/Piny/Repo.pm +++ b/libpiny/lib/Piny/Repo.pm @@ -331,23 +331,23 @@ sub rebuild_apache { my ( $s ) = @_; - my $globaltemp = File::Temp->new( ) or die "Could not create temporary file: $!"; + my $globaltemp = File::Temp->new( DIR => "/etc/apache2/piny/global/" ) or die "Could not create temporary file: $!"; $globaltemp->unlink_on_destroy( 0 ); print $globaltemp $s->apache_global_config; $globaltemp->close or die "Could not close new wikilist: $!"; - rename( $globaltemp->filename, "/etc/apache2/piny/global/" . $s->name ) or die "Could not rename apache config: $!"; + rename( $globaltemp->filename, "/etc/apache2/piny/global/" . $s->name . ".conf" ) or die "Could not rename apache config: $!"; - my $securetemp = File::Temp->new( ) or die "Could not create temporary file: $!"; + my $securetemp = File::Temp->new( DIR => "/etc/apache2/piny/secure/" ) or die "Could not create temporary file: $!"; $securetemp->unlink_on_destroy( 0 ); print $securetemp $s->apache_secure_config; $securetemp->close or die "Could not close new wikilist: $!"; - rename( $securetemp->filename, "/etc/apache2/piny/secure/" . $s->name ) or die "Could not rename apache config: $!"; + rename( $securetemp->filename, "/etc/apache2/piny/secure/" . $s->name . ".conf" ) or die "Could not rename apache config: $!"; - my $wwwtemp = File::Temp->new( ) or die "Could not create temporary file: $!"; + my $wwwtemp = File::Temp->new( DIR => "/etc/apache2/piny/www/" ) or die "Could not create temporary file: $!"; $wwwtemp->unlink_on_destroy( 0 ); print $wwwtemp $s->apache_www_config; $wwwtemp->close or die "Could not close new wikilist: $!"; - rename( $wwwtemp->filename, "/etc/apache2/piny/www/" . $s->name ) or die "Could not rename apache config: $!"; + rename( $wwwtemp->filename, "/etc/apache2/piny/www/" . $s->name . ".conf" ) or die "Could not rename apache config: $!"; if ( $s->config->piny_apachereload =~ /^(1|true)$/ ) { system( "/etc/init.d/apache2", "reload" ) and die "Could not reload apache config!"; @@ -387,7 +387,7 @@ sub rebuild_ikiwiki { system( "/usr/bin/sudo", "-H", "-u", $ikiuser->name, "/usr/bin/git", "clone", "--quiet", $s->path, $s->ikiwiki_srcdir ) and die "Could not clone repo to ikiwiki srcdir!"; }; - open( WIKILIST, ">", "/etc/ikiwiki/wikilist.d/" . $s->name ) or die "Could not create wikilist.d file: $!"; + open( WIKILIST, ">", "/etc/ikiwiki/wikilist.d/" . $s->name . ".conf" ) or die "Could not create wikilist.d file: $!"; print WIKILIST $ikiuser->name . " /etc/ikiwiki/piny/" . $s->name . ".setup\n"; close( WIKILIST ) or die "Could not close wikilist.d file: $!"; @@ -397,12 +397,12 @@ sub rebuild_ikiwiki { }; sub rebuild_wikilist { - my $temp = File::Temp->new( ) or die "Could not create temporary file: $!"; + my $temp = File::Temp->new( DIR => "/etc/ikiwiki/wikilist.d/" ) or die "Could not create temporary file: $!"; $temp->unlink_on_destroy( 0 ); my $dh = IO::Dir->new( "/etc/ikiwiki/wikilist.d" ) or die "Could not open wikilist.d directory: $!"; while ( defined ( my $entry = $dh->read ) ) { - next if ( $entry =~ /^\./ ); + next if ( $entry !~ /.conf$/ ); open( FILE, "<", "/etc/ikiwiki/wikilist.d/" . $entry ) or die "Could not open wikilist.d entry $entry: $!"; print $temp ; close( FILE ) or die "Could not close wikilist.d entry $entry: $!"; -- cgit v1.2.3