[builder] do not check if string is contained in append_to_file if doesn't exists

This commit is contained in:
mudler
2016-04-22 11:13:34 +02:00
parent 67781838d3
commit 6fcccf99b8
+8 -5
View File
@@ -60,12 +60,15 @@ sub safe_call {
sub append_to_file {
my ( $file_name, $package ) = @_;
# Check that the package was not already there
open my $fh_ro, '<:encoding(UTF-8)', $file_name or die;
while ( my $line = <$fh_ro> ) {
return if $line eq $package . "\n";
if ( -f $file_name ) {
# Check that the package was not already there
open my $fh_ro, '<:encoding(UTF-8)', $file_name or die;
while ( my $line = <$fh_ro> ) {
return if $line eq $package . "\n";
}
close $fh_ro;
}
close $fh_ro;
open( my $fh_a, '>>', $file_name )
or die "Could not open file '$filename' $!";