add success check to file writing
This commit is contained in:
@ -46,7 +46,7 @@ sub update_db_config {
|
||||
my @lines;
|
||||
my $found = 0;
|
||||
while ( my $line = <$readhandle> ) {
|
||||
if ( $line =~ /^database=/ ) {
|
||||
if ( rindex( $line, "database=", 0 ) == 0 ) {
|
||||
$line = "database=${db_prefix}_$experiment\n";
|
||||
$found = 1;
|
||||
}
|
||||
@ -54,12 +54,15 @@ sub update_db_config {
|
||||
}
|
||||
close($readhandle) or die "failed to close db.conf: $!";
|
||||
|
||||
say "Sanity check:";
|
||||
say @lines;
|
||||
|
||||
die "no database= line found in $remote_db_conf for some reason"
|
||||
unless $found;
|
||||
|
||||
open( my $writehandle, '>', $remote_db_conf )
|
||||
or die "failed to open db.conf: $!";
|
||||
print( $writehandle, @lines );
|
||||
print( $writehandle, @lines ) or die "failed to write db.conf: $!";
|
||||
close($writehandle) or die "failed to close db.conf: $!";
|
||||
|
||||
say "Updated db.conf for database $db_prefix\_$experiment";
|
||||
|
||||
Reference in New Issue
Block a user