Skip to content

Commit e4e7b9c

Browse files
authored
Fix usages of "open ... ||" (#17)
Due to operator precedence, Perl treats: | open FH, "> $file" || die 'Error'; as: | open FH, ("> $file" || die 'Error'); which will always evaluate as: | open FH, "> $file"; This change fixes those occurences, additionally using three-argument open().
1 parent 9ab30d7 commit e4e7b9c

6 files changed

Lines changed: 24 additions & 24 deletions

foomatic-cleanupdrivers.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ $0 =~ m!/([^/]+)\s*$!;
2020
$progname = $1;
2121

2222
# Read the directory with the driver's XML entries
23-
opendir DRIVERDIR, "$libdir/db/source/driver" ||
23+
opendir (DRIVERDIR, "$libdir/db/source/driver") or
2424
die "Cannot open driver XML directory!\n";
2525
my $driver;
2626
while ($driver = readdir(DRIVERDIR)) {
27-
open DRIVERENTRY, "< $libdir/db/source/driver/$driver" || die " Database entry for the driver $driver cannot be read!\n";
27+
open (DRIVERENTRY, '<', "$libdir/db/source/driver/$driver") or die " Database entry for the driver $driver cannot be read!\n";
2828
my @driverentryfield = <DRIVERENTRY>;
2929
close DRIVERENTRY;
3030
my $driverentry = join ('', @driverentryfield);

foomatic-compiledb.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ sub spawn_child {
168168
(!$db->{'dat'}{'ppdfile'})));
169169
@data = $db->getppd();
170170
}
171-
open OUTPUT, "> $filename" ||
171+
open (OUTPUT, '>', $filename) or
172172
die "Cannot write $filename!";
173173
print OUTPUT join('', @data);
174174
close OUTPUT;

foomatic-nonumericalids.in

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ for $printer (@{$db->{'overview'}}) {
6363
# Translation table to convert old numerical printer IDs to new
6464
# clear-text ones
6565
my $file = "$libdir/db/oldprinterids";
66-
open FILE, "> $file" ||
66+
open (FILE, '>', $file) or
6767
die "File $file cannot be written!\n";
6868
print FILE join('', @translationtable);
6969
close FILE;
7070
print " Wrote $file.\n";
7171

7272
# List of old printer files to be removed from CVS
7373
$file = "oldprinterfiles";
74-
open FILE, "> $file" ||
74+
open (FILE, '>', $file) or
7575
die "File $file cannot be written!\n";
7676
print FILE join('', @oldidlist);
7777
close FILE;
7878
print " Wrote $file.\n";
7979

8080
# List of files to be added to the CVS
8181
$file = "newprinterfiles";
82-
open FILE, "> $file" ||
82+
open (FILE, '>', $file) or
8383
die "File $file cannot be written!\n";
8484
print FILE join('', @newidlist);
8585
close FILE;
@@ -88,19 +88,19 @@ print " Wrote $file.\n";
8888
# Scan through all files of the database and replace all references to
8989
# numerical printer IDs to the appriopriate new IDs
9090
my @xmlfiles;
91-
opendir DIR, "$libdir/db/source/printer" ||
91+
opendir (DIR, "$libdir/db/source/printer") or
9292
die "Cannot open printer XML directory!\n";
9393
while ($file = readdir(DIR)) {
9494
push(@xmlfiles, "printer/$file") if $file =~ /^[^\.].*\.xml$/;
9595
}
9696
closedir DIR;
97-
opendir DIR, "$libdir/db/source/driver" ||
97+
opendir (DIR, "$libdir/db/source/driver") or
9898
die "Cannot open driver XML directory!\n";
9999
while ($file = readdir(DIR)) {
100100
push(@xmlfiles, "driver/$file") if $file =~ /^[^\.].*\.xml$/;
101101
}
102102
closedir DIR;
103-
opendir DIR, "$libdir/db/source/opt" ||
103+
opendir (DIR, "$libdir/db/source/opt") or
104104
die "Cannot open option XML directory!\n";
105105
while ($file = readdir(DIR)) {
106106
push(@xmlfiles, "opt/$file") if $file =~ /^[^\.].*\.xml$/;
@@ -112,7 +112,7 @@ my $chfiles = 0;
112112
my @chfilelist;
113113
for $file (@xmlfiles) {
114114
print "Processing $file";
115-
open FILE, "< $libdir/db/source/$file" ||
115+
open (FILE, '<', "$libdir/db/source/$file") or
116116
die "Database entry $file cannot be read!\n";
117117
my @lines = <FILE>;
118118
close FILE;
@@ -128,7 +128,7 @@ for $file (@xmlfiles) {
128128
}
129129
print "\n";
130130
next if !$ch;
131-
open FILE, "> $libdir/db/source/$file" ||
131+
open (FILE, '>', "$libdir/db/source/$file") or
132132
die "Database entry $file cannot be written!\n";
133133
print FILE join('', @lines);
134134
close FILE;
@@ -139,7 +139,7 @@ for $file (@xmlfiles) {
139139

140140
# List of files changed in CVS
141141
$file = "changedfiles";
142-
open FILE, "> $file" ||
142+
open (FILE, '>', $file) or
143143
die "File $file cannot be written!\n";
144144
print FILE join('', @oldidlist, @chfilelist);
145145
close FILE;

foomatic-preferred-driver.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ for $printer (@{$db->{'overview'}}) {
5959
print ": @sorted --> $sorted[0]\n";
6060
$printer->{'driver'} = $sorted[0];
6161
}
62-
open PRINTERENTRY, "< $libdir/db/source/printer/$printer->{'id'}.xml" || die " Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be read!\n";
62+
open (PRINTERENTRY, '<', "$libdir/db/source/printer/$printer->{'id'}.xml") or die " Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be read!\n";
6363
my @printerentryfield = <PRINTERENTRY>;
6464
close PRINTERENTRY;
6565

@@ -80,7 +80,7 @@ for $printer (@{$db->{'overview'}}) {
8080
$printerentry =~
8181
s!</model>!</model>\n <driver>$printer->{'driver'}</driver>!sg;
8282
}
83-
open PRINTERENTRY, "> $libdir/db/source/printer/$printer->{'id'}.xml" || die " Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be written!\n";
83+
open (PRINTERENTRY, '>', "$libdir/db/source/printer/$printer->{'id'}.xml") or die " Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be written!\n";
8484
print PRINTERENTRY $printerentry;
8585
close PRINTERENTRY;
8686
}

foomatic-printjob.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ if (!defined($in_config->{'spooler'})) {
121121
if (defined($opt_S)) {
122122
if ($> == 0) { # Program invoked as "root"?
123123
# Set system default spooler
124-
open DEFAULTFILE, "> $sysdeps->{'foo-etc'}/defaultspooler" ||
124+
open (DEFAULTFILE, '>', "$sysdeps->{'foo-etc'}/defaultspooler") or
125125
die "Cannot write $sysdeps->{'foo-etc'}/defaultspooler!\n";
126126
print DEFAULTFILE "$in_config->{'spooler'}\n";
127127
close DEFAULTFILE;
128128
exit 0;
129129
} else {
130130
# Set personal default spooler
131-
open DEFAULTFILE, "> $ENV{'HOME'}/.defaultspooler" ||
131+
open (DEFAULTFILE, '>', "$ENV{'HOME'}/.defaultspooler") or
132132
die "Cannot write $ENV{'HOME'}/.defaultspooler!\n";
133133
print DEFAULTFILE "$in_config->{'spooler'}\n";
134134
close DEFAULTFILE;
@@ -315,7 +315,7 @@ sub query_lprng {
315315
if (defined($config->{'queue'})) {
316316
$queue = " -P $config->{'queue'}";
317317
}
318-
open LPQOUTPUT, "$sysdeps->{'lpd-lpq'}$queue @ARGV |" || return 1;
318+
open (LPQOUTPUT, "$sysdeps->{'lpd-lpq'}$queue @ARGV |") or return 1;
319319
my @lpqoutput = <LPQOUTPUT>;
320320
close LPQOUTPUT;
321321
# Filter the output
@@ -643,7 +643,7 @@ sub print_pdq {
643643
my @job_contents = <STDIN>;
644644
my $i;
645645
for ($i = 0; $i < $num_copies; $i++) {
646-
open PIPE, "| $commandline" ||
646+
open (PIPE, "| $commandline") or
647647
die "Could not launch printing command!\n";
648648
print PIPE @job_contents;
649649
close PIPE;
@@ -721,7 +721,7 @@ sub query_pdq {
721721

722722
# Read in the names of all job status files in ~/.printjobs/
723723
my @jobnumbers = ();
724-
opendir PJDIR, "$ENV{'HOME'}/.printjobs" ||
724+
opendir (PJDIR, "$ENV{'HOME'}/.printjobs") or
725725
return 0; # No ~/.printjobs/ directory ==> no jobs
726726
while ($filename = readdir(PJDIR)) {
727727
if ($filename =~ m!^([0-9][0-9][0-9]).status$!) {
@@ -877,7 +877,7 @@ sub remove_pdq {
877877

878878
# Read in the names of all job status files in ~/.printjobs/
879879
my @jobnumbers = ();
880-
opendir PJDIR, "$ENV{'HOME'}/.printjobs" ||
880+
opendir (PJDIR, "$ENV{'HOME'}/.printjobs") or
881881
return 0; # No ~/.printjobs/ directory ==> no jobs
882882
while ($filename = readdir(PJDIR)) {
883883
if ($filename =~ m!^([0-9][0-9][0-9]).status$!) {

foomatic-replaceoldprinterids.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $rightpattern = $opt_r if defined($opt_r);
3838
my %idhash;
3939
my $idtable = "$libdir/db/oldprinterids";
4040
$idtable = $opt_t if $opt_t;
41-
open IDTABLE, "< $idtable" ||
41+
open (IDTABLE, '<', $idtable) or
4242
die "File $idtable cannot be read!\n";
4343
while (<IDTABLE>) {
4444
if (/^\s*(\S+)\s+(\S+)\s*$/) {
@@ -52,7 +52,7 @@ my $chfiles = 0;
5252
my @chfilelist;
5353
while (my $file = shift @ARGV) {
5454
print "Processing $file";
55-
open FILE, "< $file" ||
55+
open (FILE, '<', $file) or
5656
die "File $file cannot be read!\n";
5757
my @lines = <FILE>;
5858
close FILE;
@@ -68,7 +68,7 @@ while (my $file = shift @ARGV) {
6868
}
6969
print "\n";
7070
next if !$ch;
71-
open FILE, "> $file" ||
71+
open (FILE, '>', $file) or
7272
die "File $file cannot be written!\n";
7373
print FILE join('', @lines);
7474
close FILE;
@@ -79,7 +79,7 @@ while (my $file = shift @ARGV) {
7979

8080
# List of files changed
8181
$file = "modifiedfiles";
82-
open FILE, "> $file" ||
82+
open (FILE, '>', $file) or
8383
die "File $file cannot be written!\n";
8484
print FILE join('', @oldidlist, @chfilelist);
8585
close FILE;

0 commit comments

Comments
 (0)