Hopefully...
Neither Perl's readdir nor readdir(3posix) documents EIO as a
possible error, nor does Linux getdents(3). So relying on
readdir to detect errors via autodie(3perl) is not supported
nor possible, it seems.
Perl's closedir is supported by autodie and uses
closedir(3posix), which doesn't document EIO, either. However,
closedir(3posix) will use close(3posix). Thus in theory, EIO
can still be detected if a previous readdir failed.
use PublicInbox::Spawn qw(popen_rd run_qx);
our $LD_PRELOAD = $ENV{LD_PRELOAD}; # only valid at startup
our $DEDUPE; # set to {} to dedupe or clear cache
+use autodie qw(closedir);
sub _array ($) { ref($_[0]) eq 'ARRAY' ? $_[0] : [ $_[0] ] }
my $dir = "$path/$dn";
scan_path_coderepo($self, $base, $dir) if -d $dir;
}
+ closedir $dh;
}
sub scan_tree_coderepo ($$) {
use strict;
use v5.10.1;
use parent qw(PublicInbox::ExtSearch PublicInbox::Umask PublicInbox::Lock);
-use autodie qw(mkdir);
+use autodie qw(closedir mkdir);
use Carp qw(croak carp);
use Scalar::Util qw(blessed);
use Sys::Hostname qw(hostname);
unlink($f) if -l $f && !-e $f;
}
}
+ closedir $dh;
} elsif ($!{ENOENT}) {
mkdir $pd;
} else {
next;
}
if (-d _ && $new_st[10] > ($old_ctime - dir_adj($old_ctime))) {
- opendir(my $fh, $path) or do {
+ opendir(my $dh, $path) or do {
if ($! == ENOENT || $! == ENOTDIR) {
push @$ret, gone($self, $ident, $path);
} else {
}
next;
};
- @new_st = stat($fh) or die "fstat($path): $!";
+ @new_st = stat($dh) or die "fstat($path): $!";
if ("$old_dev $old_ino" ne "@new_st[0,1]") {
push @$ret, gone($self, $ident, $path);
next;
}
$w->[2] = $new_st[10];
- on_dir_change($self, $ret, $fh, $path, $dir_delete);
+ on_dir_change($self, $ret, $dh, $path, $dir_delete);
+ closedir $dh;
} elsif ($new_st[10] > $old_ctime) { # regular files, etc
$w->[2] = $new_st[10];
push @$ret, bless(\$path,
package PublicInbox::Inbox;
use strict;
use v5.10.1;
+use autodie qw(closedir);
use PublicInbox::Git;
use PublicInbox::MID qw(mid2path);
use PublicInbox::Eml;
my $max = max(map {
substr($_, 0, -4) + 0; # drop ".git" suffix
} grep(/\A[0-9]+\.git\z/, readdir($dh))) // return;
+ closedir $dh;
$cur = $self->{-max_git_epoch} = $max;
}
}
# pretends to be like LeiDedupe and also PublicInbox::Inbox
package PublicInbox::LeiSavedSearch;
use v5.12;
-use autodie qw(opendir);
+use autodie qw(closedir opendir);
use parent qw(PublicInbox::Lock);
use PublicInbox::Git qw(git_exe);
use PublicInbox::OverIdx;
my ($c, $o, @st);
opendir(my $dh, $lss_dir);
my @d = sort(grep(!/\A\.\.?\z/, readdir($dh)));
+ closedir $dh;
my $re = qr/\A\Q$pfx\E-\./;
for my $d (grep(/$re/, @d), grep(!/$re/, @d)) {
my $f = "$lss_dir/$d/lei.saved-search";
my $p = "$lss_dir/$d/lei.saved-search";
say $fh "\tpath = ", cquote_val($p) if -f $p;
}
+ closedir $dh;
$fh->flush or die "$fh->flush: $!";
my $cfg = $lei->cfg_dump($fh->filename);
my $out = $cfg ? $cfg->get_all('lei.q.output') : [];
package PublicInbox::MdirReader;
use strict;
use v5.10.1;
+use autodie qw(closedir);
use PublicInbox::InboxWritable qw(eml_from_path);
use PublicInbox::SHA qw(sha256_hex);
next if index($fl, 'T') >= 0; # no Trashed messages
$cb->($pfx.$bn, $fl, @arg);
}
+ closedir $dh;
}
}
my $eml = eml_from_path($f) or next;
$cb->($f, [], $eml, @arg);
}
+ closedir $dh;
}
$pfx = $dir . 'cur/';
opendir my $dh, $pfx or return;
my @kw = sort(map { $c2kw{$_} // () } split(//, $fl));
$cb->($f, \@kw, $eml, @arg);
}
+ closedir $dh;
}
sub new { bless {}, __PACKAGE__ }
package PublicInbox::WWW;
use strict;
use v5.10.1;
-use autodie qw(chdir opendir);
+use autodie qw(chdir closedir opendir);
use PublicInbox::Config;
use PublicInbox::Git;
use PublicInbox::Hval;
};
chdir $dh;
my @css = grep /\.css\z/i, readdir $dh;
+ closedir $dh;
for my $fn (@css) {
my ($key) = ($fn =~ m!([^/]+?)(?:\.css)?\z!i);
next if $css_map->{$key};
unshift @{$self->{scan_q}}, [ $dir, $dh ];
last;
} else {
+ closedir $dh;
warn "# done scanning $dir\n";
}
}
use strict;
use v5.10.1;
use parent qw(Exporter Plack::Component);
-use autodie qw(sysseek);
+use autodie qw(closedir sysseek);
use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
use HTTP::Date qw(time2str);
use HTTP::Status qw(status_message);
return r(500);
};
my @entries = grep(!/\A\./, readdir($dh));
- $dh = undef;
+ closedir $dh;
my (%dirs, %other, %want_gz);
my $path_info = $env->{PATH_INFO};
push @entries, '..' if $path_info ne '/';
if ($opt->{cow}) { # make existing $DIR/{xap,ei}* CoW
my $dfd = dup(fileno($dh)) // die "dup: $!";
open my $fh, '<&='.$dfd;
- closedir $dh;
PublicInbox::Syscall::yesdatacow_fh($fh);
}
+ closedir $dh;
die "No Xapian shards found in $old\n" unless @old_shards;
@old_shards = sort { $a <=> $b } @old_shards;
my ($src, $max_shard);