about summary refs log tree commit homepage
path: root/script
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-17 23:37:52 +0000
committerEric Wong <e@80x24.org>2023-10-18 20:50:24 +0000
commit19b791f4894efcb6e545a6b51c8147298363358f (patch)
tree16a806fcb0c8fdaef242a2d268a8b1416809b46f /script
parent35b0f7aa00a24f5d89b1b941ec644327ba074c99 (diff)
downloadpublic-inbox-19b791f4894efcb6e545a6b51c8147298363358f.tar.gz
`readline' ops may not detect errors on partial reads.
This saves us some code to reduce cognitive overhead for
readers.  We'll also support reusing a destination buffers so it
can work more nicely with existing code.
Diffstat (limited to 'script')
-rwxr-xr-xscript/public-inbox-edit4
-rwxr-xr-xscript/public-inbox-init3
2 files changed, 4 insertions, 3 deletions
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index 1fb6f32b..77028817 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -15,6 +15,7 @@ PublicInbox::Admin::check_require('-index');
 use PublicInbox::Eml;
 use PublicInbox::InboxWritable qw(eml_from_path);
 use PublicInbox::Import;
+use PublicInbox::Git qw(read_all);
 
 my $help = <<'EOF';
 usage: public-inbox-edit -m MESSAGE-ID [--all] [INBOX_DIRS]
@@ -184,8 +185,7 @@ retry_edit:
         # rename/relink $edit_fn
         open my $new_fh, '<', $edit_fn or
                 die "can't read edited file ($edit_fn): $!\n";
-        defined(my $new_raw = do { local $/; <$new_fh> }) or die
-                "read $edit_fn: $!\n";
+        my $new_raw = read_all($new_fh);
 
         if (!$opt->{raw}) {
                 PublicInbox::Eml::strip_from($new_raw);
diff --git a/script/public-inbox-init b/script/public-inbox-init
index b3a16cfb..33bee310 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -125,13 +125,14 @@ my $auto_unlink = PublicInbox::OnDestroy->new($$, sub { unlink $lockfile });
 my $perm = 0644 & ~umask;
 my %seen;
 if (-e $pi_config) {
+        require PublicInbox::Git;
         open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n";
         my @st = stat($oh);
         $perm = $st[2];
         defined $perm or die "(f)stat failed on $pi_config: $!\n";
         chmod($perm & 07777, $fh) or
                 die "(f)chmod failed on future $pi_config: $!\n";
-        defined(my $old = do { local $/; <$oh> }) or die "read $pi_config: $!\n";
+        my $old = PublicInbox::Git::read_all($oh);
         print $fh $old or die "failed to write: $!\n";
         close $oh or die "failed to close $pi_config: $!\n";