nmbug: check whether every forked process exit with (non)zero value

If any of the forked process exits with nonzero value, terminate
current operation -- nonzero exit value indicates failure and
then there is no point continuing.
This commit is contained in:
Tomi Ollila 2012-04-01 21:28:42 +03:00 committed by David Bremner
parent 00a8581e4d
commit a114ac8b77

View file

@ -60,6 +60,9 @@ sub git_pipe {
sub git { sub git {
my $fh = git_pipe (@_); my $fh = git_pipe (@_);
my $str = join ('', <$fh>); my $str = join ('', <$fh>);
unless (close $fh) {
die "'git @_' exited with nonzero value\n";
}
chomp($str); chomp($str);
return $str; return $str;
} }
@ -84,7 +87,7 @@ sub spawn {
foreach my $line (@{$ioref}) { foreach my $line (@{$ioref}) {
print $fh $line, "\n"; print $fh $line, "\n";
} }
exit 0; exit ! close $fh;
} else { } else {
if ($dir ne '|-') { if ($dir ne '|-') {
open STDIN, '<', '/dev/null' or die "reopening stdin: $!" open STDIN, '<', '/dev/null' or die "reopening stdin: $!"
@ -106,6 +109,9 @@ sub get_tags {
chomp (); chomp ();
push @tags, $_ if (m/^$prefix/); push @tags, $_ if (m/^$prefix/);
} }
unless (close $fh) {
die "'notmuch search --output=tags *' exited with nonzero value\n";
}
return @tags; return @tags;
} }
@ -173,6 +179,10 @@ sub update_index {
foreach my $pair (@{$status->{added}}) { foreach my $pair (@{$status->{added}}) {
index_tags_for_msg ($git, $pair->{id}, 'A', $pair->{tag}); index_tags_for_msg ($git, $pair->{id}, 'A', $pair->{tag});
} }
unless (close $git) {
die "'git update-index --index-info' exited with nonzero value\n";
}
} }
@ -211,8 +221,12 @@ sub index_tags {
my @tags = grep { s/^$TAGPREFIX//; } split (' ', $rest); my @tags = grep { s/^$TAGPREFIX//; } split (' ', $rest);
index_tags_for_msg ($git,$id, 'A', @tags); index_tags_for_msg ($git,$id, 'A', @tags);
} }
unless (close $git) {
close $git; die "'git update-index --index-info' exited with nonzero value\n";
}
unless (close $fh) {
die "'notmuch dump -- $query' exited with nonzero value\n";
}
return $index; return $index;
} }
@ -395,6 +409,9 @@ sub compute_status {
} else { } else {
push @deleted, $pair; push @deleted, $pair;
} }
unless (close $fh) {
die "'notmuch search --output=files id:$id' exited with nonzero value\n";
}
} }
@ -414,7 +431,12 @@ sub diff_index {
qw/diff-index --cached/, qw/diff-index --cached/,
"--diff-filter=$filter", qw/--name-only HEAD/ ); "--diff-filter=$filter", qw/--name-only HEAD/ );
return unpack_diff_lines ($fh); my @lines = unpack_diff_lines ($fh);
unless (close $fh) {
die "'git diff-index --cached --diff-filter=$filter --name-only HEAD' ",
"exited with nonzero value\n";
}
return @lines;
} }
@ -426,7 +448,12 @@ sub diff_refs {
my $fh= git_pipe ( 'diff', "--diff-filter=$filter", '--name-only', my $fh= git_pipe ( 'diff', "--diff-filter=$filter", '--name-only',
$ref1, $ref2); $ref1, $ref2);
return unpack_diff_lines ($fh); my @lines = unpack_diff_lines ($fh);
unless (close $fh) {
die "'git diff --diff-filter=$filter --name-only $ref1 $ref2' ",
"exited with nonzero value\n";
}
return @lines;
} }