diff --git a/Build.pm b/Build.pm index 023ea0c2..a243f4e5 100644 --- a/Build.pm +++ b/Build.pm @@ -336,10 +336,9 @@ sub find_config_file { sub slurp_config_file { my ($file, $seen) = @_; - local *CONF; - die("$file: $!\n") unless open(CONF, '<', $file); - my @config = ; - close CONF; + die("$file: $!\n") unless open(my $conffd, '<', $file); + my @config = <$conffd>; + close $conffd; chomp @config; if (@config && $config[0] =~ /^#!PrependConfigFile:\s*([^\.\/][^\/]*?)\s*$/) { my $otherfile = $1; @@ -379,10 +378,9 @@ sub read_config { if (ref($cfile)) { @config = @$cfile; } elsif (defined($cfile)) { - local *CONF; - return undef unless open(CONF, '<', $cfile); - @config = ; - close CONF; + return undef unless open(my $conffd, '<', $cfile); + @config = <$conffd>; + close $conffd; chomp @config; } # create verbatim macro blobs diff --git a/Build/Arch.pm b/Build/Arch.pm index 3436c3df..5233aa84 100644 --- a/Build/Arch.pm +++ b/Build/Arch.pm @@ -87,14 +87,14 @@ sub get_assets { sub parse { my ($config, $pkgbuild) = @_; my $ret; - local *PKG; - if (!open(PKG, '<', $pkgbuild)) { + my $pkgfd; + if (!open($pkgfd, '<', $pkgbuild)) { $ret->{'error'} = "$pkgbuild: $!"; return $ret; } my %vars; my @ifs; - while () { + while (<$pkgfd>) { chomp; next if /^\s*$/; next if /^\s*#/; @@ -127,7 +127,7 @@ sub parse { my $val = $4; if ($3) { while ($val !~ s/\)\s*(?:#.*)?$//s) { - my $nextline = ; + my $nextline = <$pkgfd>; last unless defined $nextline; chomp $nextline; $val .= ' ' . $nextline; @@ -139,7 +139,7 @@ sub parse { $vars{$var} = [ unquotesplit($val, \%vars) ]; } } - close PKG; + close $pkgfd; $ret->{'name'} = $vars{'pkgname'}->[0] if $vars{'pkgname'}; $ret->{'version'} = $vars{'pkgver'}->[0] if $vars{'pkgver'}; $ret->{'deps'} = []; @@ -170,21 +170,19 @@ sub parse { sub islzma { my ($fn) = @_; - local *F; - return 0 unless open(F, '<', $fn); + return 0 unless open(my $fd, '<', $fn); my $h; - return 0 unless read(F, $h, 5) == 5; - close F; + return 0 unless read($fd, $h, 5) == 5; + close $fd; return $h eq "\3757zXZ"; } sub iszstd { my ($fn) = @_; - local *F; - return 0 unless open(F, '<', $fn); + return 0 unless open(my $fd, '<', $fn); my $h; - return 0 unless read(F, $h, 4) == 4; - close F; + return 0 unless read($fd, $h, 4) == 4; + close $fd; return $h eq "(\265\057\375"; } @@ -367,17 +365,15 @@ sub queryinstalled { my ($root, %opts) = @_; $root = '' if !defined($root) || $root eq '/'; - local *D; - local *F; - opendir(D, "$root/var/lib/pacman/local") || return []; - my @pn = sort(grep {!/^\./} readdir(D)); - closedir(D); + opendir(my $dirfd, "$root/var/lib/pacman/local") || return []; + my @pn = sort(grep {!/^\./} readdir($dirfd)); + closedir($dirfd); my @pkgs; for my $pn (@pn) { - next unless open(F, '<', "$root/var/lib/pacman/local/$pn/desc"); + next unless open(my $fd, '<', "$root/var/lib/pacman/local/$pn/desc"); my $data = ''; - 1 while sysread(F, $data, 8192, length($data)); - close F; + 1 while sysread($fd, $data, 8192, length($data)); + close $fd; my $d = parserepodata(undef, $data); next unless defined $d->{'name'}; my $q = {}; diff --git a/Build/Collax.pm b/Build/Collax.pm index 2fc332c4..1b3576d2 100644 --- a/Build/Collax.pm +++ b/Build/Collax.pm @@ -24,13 +24,13 @@ sub parse { } elsif (ref($fn) ne "") { die "Unhandled ref type in collax"; } else { - local *FH; - if (!open(FH, "<", $fn)) { + my $fd; + if (!open($fd, "<", $fn)) { return {"error" => "$fn: $!"}; } - @bscript = ; + @bscript = <$fd>; chomp(@bscript); - close(FH); + close($fd); } my $ret = {"deps" => []}; diff --git a/Build/Deb.pm b/Build/Deb.pm index 7ae256b5..6d402345 100644 --- a/Build/Deb.pm +++ b/Build/Deb.pm @@ -81,10 +81,9 @@ sub parse { if (ref($fn) eq 'ARRAY') { @control = @$fn; } else { - local *F; - return { 'error' => "$fn: $!" } unless open(F, '<', $fn); - @control = ; - close F; + return { 'error' => "$fn: $!" } unless open(my $fd, '<', $fn); + @control = <$fd>; + close $fd; chomp @control; } splice(@control, 0, 3) if @control > 3 && $control[0] =~ /^-----BEGIN/; diff --git a/Build/Docker.pm b/Build/Docker.pm index 99b9d6fc..f7916d83 100644 --- a/Build/Docker.pm +++ b/Build/Docker.pm @@ -41,11 +41,10 @@ sub gettargetarch { sub slurp { my ($fn) = @_; - local *F; - return undef unless open(F, '<', $fn); + return undef unless open(my $fd, '<', $fn); local $/ = undef; # Perl slurp mode - my $content = ; - close F; + my $content = <$fd>; + close $fd; return $content; } diff --git a/PBuild/BuildResult.pm b/PBuild/BuildResult.pm index fab094f1..25c4c42a 100644 --- a/PBuild/BuildResult.pm +++ b/PBuild/BuildResult.pm @@ -41,11 +41,10 @@ sub read_bininfo { my ($dir, $withid) = @_; my $bininfo; my @bininfo_s; - local *BI; - if (open(BI, '<', "$dir/.bininfo")) { - @bininfo_s = stat(BI); - $bininfo = PBuild::Util::retrieve(\*BI, 1) if @bininfo_s && $bininfo_s[7]; - close BI; + if (open(my $bifd, '<', "$dir/.bininfo")) { + @bininfo_s = stat($bifd); + $bininfo = PBuild::Util::retrieve($bifd, 1) if @bininfo_s && $bininfo_s[7]; + close $bifd; if ($bininfo) { $bininfo->{'.bininfo'} = {'id' => "$bininfo_s[9]/$bininfo_s[7]/$bininfo_s[1]"} if $withid; return $bininfo; @@ -65,13 +64,12 @@ sub read_bininfo { my $r = {%$d, 'filename' => $file, 'id' => "$s[9]/$s[7]/$s[1]"}; $bininfo->{$file} = $r; } elsif ($file =~ /[-.]appdata\.xml$/) { - local *F; - open(F, '<', "$dir/$file") || next; - my @s = stat(F); + open(my $fd, '<', "$dir/$file") || next; + my @s = stat($fd); next unless @s; my $ctx = Digest::MD5->new; - $ctx->addfile(*F); - close F; + $ctx->addfile($fd); + close $fd; $bininfo->{$file} = {'md5sum' => $ctx->hexdigest(), 'filename' => $file, 'id' => "$s[9]/$s[7]/$s[1]"}; } next; diff --git a/PBuild/Checker.pm b/PBuild/Checker.pm index 1bd068b9..e22eaad9 100644 --- a/PBuild/Checker.pm +++ b/PBuild/Checker.pm @@ -598,10 +598,10 @@ sub check { my $mylastcheck = $lastcheck->{$packid}; my @meta; if (!@meta_s || !$mylastcheck || substr($mylastcheck, 96) ne "$meta_s[9]/$meta_s[7]/$meta_s[1]") { - if (open(F, '<', "$dst/_meta")) { - @meta_s = stat F; - @meta = ; - close F; + if (open(my $fd, '<', "$dst/_meta")) { + @meta_s = stat $fd; + @meta = <$fd>; + close $fd; chomp @meta; $mylastcheck = substr($meta[0], 0, 32); if (@meta == 2 && $meta[1] =~ /^fake/) { @@ -661,9 +661,9 @@ sub check { goto relsynccheck; } # something changed, read in old meta (if not already done) - if (!@meta && open(F, '<', "$dst/_meta")) { - @meta = ; - close F; + if (!@meta && open(my $fd, '<', "$dst/_meta")) { + @meta = <$fd>; + close $fd; chomp @meta; } if ($incycle == 1) { diff --git a/PBuild/Container.pm b/PBuild/Container.pm index 5ca59214..65de99be 100644 --- a/PBuild/Container.pm +++ b/PBuild/Container.pm @@ -55,17 +55,16 @@ sub containerinfo2obsbinlnk { } eval { PBuild::Verify::verify_nevraquery($lnk); PBuild::Verify::verify_filename($d->{'file'}) }; return undef if $@; - local *F; if ($d->{'tar_md5sum'}) { # this is a normalized container $lnk->{'hdrmd5'} = $d->{'tar_md5sum'}; $lnk->{'lnk'} = $d->{'file'}; return $lnk; } - return undef unless open(F, '<', "$dir/$d->{'file'}"); + return undef unless open(my $fd, '<', "$dir/$d->{'file'}"); my $ctx = Digest::MD5->new; - $ctx->addfile(*F); - close F; + $ctx->addfile($fd); + close $fd; $lnk->{'hdrmd5'} = $ctx->hexdigest(); $lnk->{'lnk'} = $d->{'file'}; return $lnk; diff --git a/createdirdeps b/createdirdeps index 3d0e12e6..01c58fe3 100755 --- a/createdirdeps +++ b/createdirdeps @@ -48,20 +48,20 @@ sub queryfromfilename { my ($opts, @args) = Build::Options::parse_options($options, @ARGV); my %old; -if (defined($opts->{'oldfile'}) && open(F, '<', $opts->{'oldfile'})) { - while () { +if (defined($opts->{'oldfile'}) && open(my $fd, '<', $opts->{'oldfile'})) { + while (<$fd>) { chomp; $old{$1} = $_ if /^([PRrCOI]:[^ ]+): /; } - close F; + close $fd; } my %seen; for my $dir (@args) { my $cmd = "find $dir -follow -type f \\( -name \"*.rpm\" -o -name \"*.deb\" -o -name \"*.pkg.tar.gz\" -o -name \"*.pkg.tar.xz\" \\) -a ! -name \"*src.rpm\" -printf '\%T@/\%s/\%i \%p\\n'"; - open(F, '-|', $cmd) or next; - while () { + open(my $fd, '-|', $cmd) or next; + while (<$fd>) { chomp; next unless /^([\d\.]+\/\d+\/\d+) (.*)$/; my $id = $1; @@ -94,6 +94,6 @@ for my $dir (@args) { $q->{'location'} = $path; Build::writedeps(\*STDOUT, $q); } - close F; + close $fd; } diff --git a/killchroot b/killchroot index 330b7c76..3e8ecfbd 100755 --- a/killchroot +++ b/killchroot @@ -65,8 +65,8 @@ my %pids; my $pid; my $path; -opendir(D, "/proc") || die("/proc: $!\n"); -for $pid (readdir(D)) { +opendir(my $dirfd, "/proc") || die("/proc: $!\n"); +for $pid (readdir($dirfd)) { next unless $pid =~ /^\d+$/; $path = readlink("/proc/$pid/root"); next unless defined $path; @@ -78,7 +78,7 @@ for $pid (readdir(D)) { $pids{$pid} = 1; } } -closedir(D); +closedir($dirfd); my @pids = sort keys %pids; exit 0 unless @pids; @@ -88,10 +88,10 @@ print "$msg\n" if $msg ne ''; if ($verbose) { my @pidsv = (); for $pid (@pids) { - open(F, "; } else { - local *F; - open(F, '<', $manifest) || die("$manifest: $!\n"); - @p = ; - close F; + open(my $fd, '<', $manifest) || die("$manifest: $!\n"); + @p = <$fd>; + close $fd; } chomp @p; } diff --git a/substitutedeps b/substitutedeps index 1fa567d6..66648f60 100755 --- a/substitutedeps +++ b/substitutedeps @@ -106,7 +106,7 @@ my %neg = map {$_ => 1} @neg; @sdeps = grep {!$neg{$_}} @sdeps; my %sdeps = map {$_ => 1} @sdeps; -open(F, '>', $newspec) || die("$newspec: $!\n"); +open(my $fd, '>', $newspec) || die("$newspec: $!\n"); my $inchangelog = 0; my $mainpkg = ''; @@ -193,15 +193,15 @@ for my $line (@$xspec) { if ($file =~ /\//s || $file =~ /^\./) { $suffix = "error:illegal release suffix"; } else { - if (open(RP, '<', "$specdir$file")) { + if (open(my $rpfd, '<', "$specdir$file")) { $suffix = "error:no suffix in $file"; - for () { + for (<$rpfd>) { chomp; s/^\s+//; s/\s+$//; $suffix = $_ if $_ && !/^#/; } - close RP; + close $rpfd; } else { $suffix = "error:$file file does not exist"; } @@ -230,9 +230,9 @@ for my $line (@$xspec) { $::ENV{'BUILD_OLDRELEASE'} = $oldl; my @nl; my $interpreter = "/bin/bash"; - if (open(RP, '<', "$specdir$cf->{'releaseprg'}")) { - @nl = ; - close RP; + if (open(my $rpfd, '<', "$specdir$cf->{'releaseprg'}")) { + @nl = <$rpfd>; + close $rpfd; if (@nl && $nl[0] =~ /^#!\s*(\S*)/) { $interpreter = $1; } @@ -288,13 +288,13 @@ for my $line (@$xspec) { if (!$used || ($line !~ /^(?:Requires|BuildRequires|PreReq)(?:\([^\)]+\))?:/i)) { $line = $origline if defined $origline; - print F "$line\n"; + print $fd "$line\n"; next; } if ($line =~ /%\(/) { # too hard for us $line = $origline if defined $origline; - print F "$line\n"; + print $fd "$line\n"; next; } @@ -305,7 +305,7 @@ for my $line (@$xspec) { if ($r =~ /^\(/) { # no rich dependency support for now $line = $origline if defined $origline; - print F "$line\n"; + print $fd "$line\n"; next; } my @deps = $r =~ /([^\s\[,]+)(\s+[<=>]+\s+[^\s\[,]+)?[\s,]*/g; @@ -340,24 +340,24 @@ for my $line (@$xspec) { } if ($replace) { $line =~ /^(.*?:\s*)/; - print F $1.join(' ', @ndeps) if @ndeps; - print F "\n"; + print $fd $1.join(' ', @ndeps) if @ndeps; + print $fd "\n"; } else { $line = $origline if defined $origline; - print F "$line\n"; + print $fd "$line\n"; } } if ($changelog) { - print F "%changelog\n"; - if (open(CF, '<', $changelog)) { - while() { - print F $_; + print $fd "%changelog\n"; + if (open(my $cf, '<', $changelog)) { + while(<$cf>) { + print $fd $_; } - close CF; + close $cf; } } -close(F) || die("close: $!\n"); +close($cf) || die("close: $!\n"); exit(0); diff --git a/unpackarchive b/unpackarchive index 628f9a8e..496d135e 100755 --- a/unpackarchive +++ b/unpackarchive @@ -530,8 +530,7 @@ sub handle_decompression { my @decomp = detect_decompressor($first16bytes); @decomp = ('cat') if $force_pipe && !@decomp; return $first16bytes unless @decomp; - local *F; - open(F, "<&STDIN") || die("stdin dup: $!\n"); + open(my $fd, "<&STDIN") || die("stdin dup: $!\n"); my $pid = open(STDIN, '-|'); die("fork: $!\n") unless defined $pid; if (!$pid) { @@ -548,7 +547,7 @@ sub handle_decompression { print G $first16bytes if $first16bytes ne ''; while (1) { my $d = ''; - my $r = read(F, $d, 8192); + my $r = read($fd, $d, 8192); next if !defined($r) && $! == POSIX::EINTR; die("read error: $!\n") unless defined $r; exit(0) unless $r; @@ -557,7 +556,7 @@ sub handle_decompression { close(G) || die("pipe close: $!\n"); exit 0; } - close(F); + close($fd); return undef; }