diff --git a/mozilla/config/build-list.pl b/mozilla/config/build-list.pl index b622290a930..32c1d3d8bdb 100755 --- a/mozilla/config/build-list.pl +++ b/mozilla/config/build-list.pl @@ -25,7 +25,7 @@ # A generic script to add entries to a file # if the entry does not already exist # -# Usage: $0 [-l] +# Usage: $0 [-l] [ ] # # -l do not attempt flock the file. @@ -38,7 +38,6 @@ sub usage() { exit(1); } -$lockfile = $nofilelocks = 0; getopts("l"); @@ -46,7 +45,11 @@ getopts("l"); $nofilelocks = 1 if defined($::opt_l); $file = shift; -$entry = shift; + +undef @entrylist; +while ($entry = shift) { + push @entrylist, $entry; +} $lockfile = $file . ".lck"; @@ -57,19 +60,36 @@ if ( ! -e "$file") { } # This needs to be atomic -open(OUT, ">>$file") || die ("$file: $!\n"); mozLock($lockfile) unless $nofilelocks; -open(RES, "grep -c '^$entry\$' $file |") or $err = $!; -if ($err) { - flock(OUT,LOCK_UN) unless $nofilelocks; - die ("grep: $err\n"); + +# Read entire file into mem +undef @inbuf; +if ( -e "$file" ) { + open(IN, "$file") || die ("$file: $!\n"); + while ($tmp = ) { + chomp($tmp); + push @inbuf, $tmp; + } + close(IN); } -chomp($val = ); -close(RES); -if (!$val) { - print OUT "$entry\n"; + +undef @outbuf; +# Add each entry to file if it's not already there +foreach $entry (@entrylist) { + push @outbuf, $entry if (!grep(/^$entry$/, @inbuf)); } + +$count = $#outbuf + 1; + +# Append new entry to file +if ($count) { + open(OUT, ">>$file") || die ("$file: $!\n"); + foreach $entry (@outbuf) { + print OUT "$entry\n"; + } + close(OUT); +} + mozUnlock($lockfile) unless $nofilelocks; -close(OUT); exit(0);