commit 945f0333b57b269fdbe5bfab1319b6b61264c268 from: Omar Polo date: Wed Jun 29 16:32:11 2022 UTC adjust writepass so gpg2 don't see the output file gpg has an annoying "feature": it avoids to overwrite files. If in interactive mode, "gpg2 -o foo" will ask the user whether to override foo or not, otherwise will just refuse to work. not nice. working around this by making gpg2 write to stdout, and redirecting stdout to that file. Then restore stdout for sanity :) While here, also make `writepass' fail if gpg fails. commit - 03eca9962f0b494ace0ac322b84ba2d3b4bdd1b4 commit + 945f0333b57b269fdbe5bfab1319b6b61264c268 blob - f3d64d88f8b43125ece9b9b6a53fafc01238207e blob + 7084c7936e992d974911e1ee4b9d9b25e13e3f91 --- plass +++ plass @@ -124,11 +124,20 @@ sub writepass { mkdirs(dirname $file); + # temporary redirect stdout to $file + open(my $stdout, '>&', STDOUT); + open(STDOUT, '>', $file); + my @args = ($gpg, @gpg_flags, '-e', '-r', recipient(), - '-o', $file); + '-o', '-'); open my $fh, '|-', @args; say $fh "$pass"; close($fh); + my $ok = !$?; + + open(STDOUT, '>&', $stdout); # restore stdout + + die "failed to run $gpg\n" unless $ok; } sub recipient {