Sun Aug 14 03:18:37 2022 UTC ()
lintpkgsrc: properly clean up after chdir

When running 'lintpkgsrc -I tmp/lp-85 -yro', lintpkgsrc couldn't find
the cache file due to the intermediate chdir($pkgdistdir).


(rillig)
diff -r1.90 -r1.91 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl

cvs diff -r1.90 -r1.91 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl (expand / switch to unified diff)

--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl 2022/08/14 03:12:02 1.90
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl 2022/08/14 03:18:36 1.91
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#!@PERL5@ 1#!@PERL5@
2# $NetBSD: lintpkgsrc.pl,v 1.90 2022/08/14 03:12:02 rillig Exp $ 2# $NetBSD: lintpkgsrc.pl,v 1.91 2022/08/14 03:18:36 rillig Exp $
3 3
4# Written by David Brownlee <abs@netbsd.org>. 4# Written by David Brownlee <abs@netbsd.org>.
5# 5#
6# Caveats: 6# Caveats:
7# The 'Makefile parsing' algorithm used to obtain package versions and 7# The 'Makefile parsing' algorithm used to obtain package versions and
8# DEPENDS information is geared towards speed rather than perfection, 8# DEPENDS information is geared towards speed rather than perfection,
9# though it has gotten somewhat better over time, it only parses the 9# though it has gotten somewhat better over time, it only parses the
10# simpler Makefile conditionals. 10# simpler Makefile conditionals.
11# 11#
12# TODO: Handle fun DEPENDS like avifile-devel with 12# TODO: Handle fun DEPENDS like avifile-devel with
13# {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1} 13# {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1}
14 14
15use v5.36; 15use v5.36;
@@ -1181,26 +1181,27 @@ sub scan_pkgsrc_distfiles_vs_distinfo($p @@ -1181,26 +1181,27 @@ sub scan_pkgsrc_distfiles_vs_distinfo($p
1181 1181
1182 if ($check_unref && %unref_distfiles) { 1182 if ($check_unref && %unref_distfiles) {
1183 verbose(scalar(keys %unref_distfiles), 1183 verbose(scalar(keys %unref_distfiles),
1184 " unreferenced file(s) in '$pkgdistdir':\n"); 1184 " unreferenced file(s) in '$pkgdistdir':\n");
1185 print join("\n", sort keys %unref_distfiles), "\n"; 1185 print join("\n", sort keys %unref_distfiles), "\n";
1186 } 1186 }
1187 1187
1188 if ($check_distinfo) { 1188 if ($check_distinfo) {
1189 if (@distwarn) { 1189 if (@distwarn) {
1190 verbose(@distwarn); 1190 verbose(@distwarn);
1191 } 1191 }
1192 1192
1193 verbose("checksum mismatches\n"); 1193 verbose("checksum mismatches\n");
 1194 my $prev_cwd = getcwd() or die;
1194 chdir_or_fail($pkgdistdir); 1195 chdir_or_fail($pkgdistdir);
1195 foreach my $sum (keys %sumfiles) { 1196 foreach my $sum (keys %sumfiles) {
1196 if ($sum eq 'Size') { 1197 if ($sum eq 'Size') {
1197 foreach my $file (@{$sumfiles{$sum}}) { 1198 foreach my $file (@{$sumfiles{$sum}}) {
1198 if (!-f $file || -S $file != $distfiles{$file}{sum}) { 1199 if (!-f $file || -S $file != $distfiles{$file}{sum}) {
1199 print $file, " (Size)\n"; 1200 print $file, " (Size)\n";
1200 $unref_distfiles{$file} = 1; 1201 $unref_distfiles{$file} = 1;
1201 } 1202 }
1202 } 1203 }
1203 next; 1204 next;
1204 } 1205 }
1205 1206
1206 my $pid = open3(my $in, my $out, undef, 'xargs', 'digest', $sum); 1207 my $pid = open3(my $in, my $out, undef, 'xargs', 'digest', $sum);
@@ -1215,27 +1216,27 @@ sub scan_pkgsrc_distfiles_vs_distinfo($p @@ -1215,27 +1216,27 @@ sub scan_pkgsrc_distfiles_vs_distinfo($p
1215 } 1216 }
1216 while (<$out>) { 1217 while (<$out>) {
1217 if (m/^$sum ?\(([^\)]+)\) = (\S+)/) { 1218 if (m/^$sum ?\(([^\)]+)\) = (\S+)/) {
1218 if ($distfiles{$1}{sum} ne $2) { 1219 if ($distfiles{$1}{sum} ne $2) {
1219 print $1, " ($sum)\n"; 1220 print $1, " ($sum)\n";
1220 $unref_distfiles{$1} = 1; 1221 $unref_distfiles{$1} = 1;
1221 } 1222 }
1222 } 1223 }
1223 } 1224 }
1224 close($out); 1225 close($out);
1225 waitpid($pid, 0) || fail "xargs digest $sum"; 1226 waitpid($pid, 0) || fail "xargs digest $sum";
1226 waitpid($pid2, 0) || fail 'pipe write to xargs'; 1227 waitpid($pid2, 0) || fail 'pipe write to xargs';
1227 } 1228 }
1228 chdir_or_fail('/'); # Do not want to stay in $pkgdistdir 1229 chdir_or_fail($prev_cwd);
1229 } 1230 }
1230 1231
1231 sort keys %unref_distfiles; 1232 sort keys %unref_distfiles;
1232} 1233}
1233 1234
1234sub store_pkgdb_in_cache($db, $fname) { 1235sub store_pkgdb_in_cache($db, $fname) {
1235 open(STORE, '>', $fname) 1236 open(STORE, '>', $fname)
1236 or die("Cannot save package data to $fname: $!\n"); 1237 or die("Cannot save package data to $fname: $!\n");
1237 foreach my $pkgver ($db->pkgvers_all) { 1238 foreach my $pkgver ($db->pkgvers_all) {
1238 my $pkgbase = $pkgver->pkgbase; 1239 my $pkgbase = $pkgver->pkgbase;
1239 my $pkgversion = $pkgver->pkgversion; 1240 my $pkgversion = $pkgver->pkgversion;
1240 1241
1241 $pkgbase =~ /^\S+$/ 1242 $pkgbase =~ /^\S+$/