commit 1169deba9daca5ae8f560bf4cc3e405435a5e1e0 from: Omar Polo date: Sat Jan 21 16:46:46 2023 UTC refactor cmd_tee: simplify the code inline (with tweaks) writepass, it's redundant to have. While here also read/write blockwise instead that of linewise. commit - 77ea6ba189318aa615484e5dbcb7271af75eb89f commit + 1169deba9daca5ae8f560bf4cc3e405435a5e1e0 blob - 61c6a6aa791f765e0f409cf13ebf0ff3b345d994 blob + 650ecafe19a2834b8fece433bc926b3fb932a85c --- plass +++ plass @@ -80,27 +80,6 @@ sub mkdirs { unless -d $dir; } -sub writepass { - my ($file, $pass) = @_; - - mkdirs(dirname $file); - - # temporary redirect stdout to $file - open(my $stdout, '>&', STDOUT); - open(STDOUT, '>', $file); - - my @args = ($gpg, @gpg_flags, '-e', '-r', recipient(), - '-o', '-'); - open my $fh, '|-', @args; - print $fh "$pass"; - close($fh); - my $ok = !$?; - - open(STDOUT, '>&', $stdout); # restore stdout - - die "failed to run $gpg\n" unless $ok; -} - sub recipient { open my $fh, '<', "$store/.gpg-id" or die "can't open recipient file"; @@ -277,14 +256,20 @@ sub cmd_tee { my $file = name2file $name; my $msg = -f $file ? "update $name" : "+$name"; + mkdirs(dirname $file); - my $pass = ""; - $pass .= $_ while ; - die "No content!\n" if $pass eq ""; + my @args = ($gpg, @gpg_flags, '-e', '-r', recipient(), + '--batch', '--yes', '-o', $file); + open my $fh, '|-', @args; - writepass($file, $pass); + local $/ = \1024; + while () { + print $fh $_; + print $_ unless $q; + } + close($fh); + exit $? if $?; got_add $file; got_ci $msg; - print $pass unless $q; }