From 5d9dcc31959d520d3e7bed3f68871245bc915ca3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 15 Sep 2021 21:35:57 +0000 Subject: clone|fetch|--mirror: add convenience $INBOX_DIR/Makefile Since the beginning of time, I've been dropping Makefiles in $INBOX_DIR (and above hiearchies) to organize groups of commands. make(1) is widely available in various flavors and a familiar tool for our target audience. It is easy to run in the right directory, typically has built-in shell completion, and doesn't silently ignore errors by default like Bourne shell. --- lib/PublicInbox/Fetch.pm | 3 ++- lib/PublicInbox/LeiMirror.pm | 61 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/Fetch.pm b/lib/PublicInbox/Fetch.pm index 0539fe50..184b4f26 100644 --- a/lib/PublicInbox/Fetch.pm +++ b/lib/PublicInbox/Fetch.pm @@ -91,7 +91,7 @@ sub get_fingerprint2 { Digest::SHA::sha256(do { local $/; <$rd> }); } -sub do_fetch { +sub do_fetch { # main entry point my ($cls, $lei, $cd) = @_; my $ibx_ver; $lei->{curl} //= PublicInbox::LeiCurl->new($lei) or return; @@ -124,6 +124,7 @@ Unable to infer inbox URL from <$git_url> EOM $ibx_uri = URI->new($inbox_url); } + PublicInbox::LeiMirror::write_makefile($dir, $ibx_ver); $lei->qerr("# inbox URL: $ibx_uri/"); my $res = do_manifest($lei, $dir, $ibx_uri) or return; my ($code, $v1_path, $v2_epochs, $muri, $ft, $mf) = @$res; diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index c113c9de..23a2156c 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -9,7 +9,7 @@ use parent qw(PublicInbox::IPC); use IO::Uncompress::Gunzip qw(gunzip $GunzipError); use PublicInbox::Spawn qw(popen_rd spawn run_die); use File::Temp (); -use Fcntl qw(SEEK_SET); +use Fcntl qw(SEEK_SET O_CREAT O_EXCL O_WRONLY); sub do_finish_mirror { # dwaitpid callback my ($arg, $pid) = @_; @@ -201,6 +201,7 @@ sub clone_v1 { my $cerr = run_reap($lei, $cmd, $opt); return $lei->child_error($cerr, "@$cmd failed") if $cerr; _try_config($self); + write_makefile($self->{dst}, 1); index_cloned_inbox($self, 1); } @@ -234,6 +235,7 @@ failed to extract epoch number from $src my $mg = PublicInbox::MultiGit->new($dst, 'all.git', 'git'); $mg->fill_alternates; for my $i ($mg->git_epochs) { $mg->epoch_cfg_set($i) } + write_makefile($self->{dst}, 2); undef $on_destroy; # unlock index_cloned_inbox($self, 2); } @@ -356,4 +358,61 @@ sub ipc_atfork_child { $self->SUPER::ipc_atfork_child; } +sub write_makefile { + my ($dir, $ibx_ver) = @_; + my $f = "$dir/Makefile"; + if (sysopen my $fh, $f, O_CREAT|O_EXCL|O_WRONLY) { + print $fh <