Commit 0b10ea17 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Copyedit: Avoid bareword filehandles.

parent 9d31cceb
......@@ -726,10 +726,12 @@ sub _save_idx {
return unless $lst;
open INDEXF, '>', $index
or die sprintf 'Couldn\'t overwrite index %s: %s', $index, $!;
print INDEXF "$lst\n";
close INDEXF;
if (open my $fh, '>', $index) {
print $fh "$lst\n";
close $fh;
} else {
die sprintf 'Couldn\'t overwrite index %s: %s', $index, $ERRNO;
}
}
# Create the 'index' file for one archive subdir
......@@ -739,18 +741,16 @@ sub _create_idx {
my $arc_txt_dir = $arc_dir . '/arctxt';
unless (opendir(DIR, $arc_txt_dir)) {
$log->syslog('err', 'Failed to open directory "%s"', $arc_txt_dir);
if (opendir my $dh, $arc_txt_dir) {
my @files = sort { $a <=> $b; } grep {/^\d+$/} readdir $dh;
closedir $dh;
my $index = $files[$#files] || 0;
_save_idx($arc_dir . '/index', $index);
return $index;
} else {
$log->syslog('err', 'Failed to open directory %s: %m', $arc_txt_dir);
return undef;
}
my @files = (sort { $a <=> $b; } grep(/^\d+$/, (readdir DIR)));
my $index = $files[$#files] || 0;
_save_idx($arc_dir . '/index', $index);
closedir DIR;
return $index;
}
# Old name: clean_archive_directory().
......@@ -778,10 +778,11 @@ sub _clean_archive_directory {
);
return undef;
}
if (opendir ARCDIR, $answer->{'cleaned_dir'}) {
if (opendir my $dh, $answer->{'cleaned_dir'}) {
my $files_left_uncleaned = 0;
foreach my $file (readdir(ARCDIR)) {
next if ($file =~ /^\./);
foreach my $file (readdir $dh) {
next if $file =~ /^\./;
$files_left_uncleaned++
unless _clean_archived_message(
$self->{context}->{'domain'}, #FIXME
......@@ -789,7 +790,7 @@ sub _clean_archive_directory {
$answer->{'cleaned_dir'} . '/' . $file
);
}
closedir ARCDIR;
closedir $dh;
if ($files_left_uncleaned) {
$log->syslog('err',
'HTML cleaning failed for %s files in the directory %s',
......@@ -823,9 +824,9 @@ sub _clean_archived_message {
}
if ($message->clean_html) {
if (open TMP, '>', $output) {
print TMP $message->as_string;
close TMP;
if (open my $fh, '>', $output) {
print $fh $message->as_string;
close $fh;
return 1;
} else {
$log->syslog(
......@@ -890,12 +891,13 @@ sub html_format {
}
my $msg_file = $destination_dir . '/msg00000.txt';
unless (open OUT, '>', $msg_file) {
if (open my $fh, '>', $msg_file) {
print $fh $msg_as_string;
close $fh;
} else {
$log->syslog('notice', 'Can\'t open %s', $msg_file);
return undef;
}
print OUT $msg_as_string;
close OUT;
# mhonarc require du change workdir so this proc must retore it
my $pwd = Cwd::getcwd();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment