From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 436D81F9FF for ; Sun, 28 Mar 2021 09:01:25 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 02/12] lei init: split out into separate file Date: Sun, 28 Mar 2021 09:01:14 +0000 Message-Id: <20210328090124.3541-3-e@80x24.org> In-Reply-To: <20210328090124.3541-1-e@80x24.org> References: <20210328090124.3541-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is a rarely-needed command, so keep it separate file so it's easier-to-find and maybe saves a bit of RAM. --- MANIFEST | 1 + lib/PublicInbox/LEI.pm | 32 ----------------------------- lib/PublicInbox/LeiInit.pm | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 lib/PublicInbox/LeiInit.pm diff --git a/MANIFEST b/MANIFEST index 64b3626f..9048b900 100644 --- a/MANIFEST +++ b/MANIFEST @@ -188,6 +188,7 @@ lib/PublicInbox/LeiDedupe.pm lib/PublicInbox/LeiExternal.pm lib/PublicInbox/LeiHelp.pm lib/PublicInbox/LeiImport.pm +lib/PublicInbox/LeiInit.pm lib/PublicInbox/LeiInput.pm lib/PublicInbox/LeiLsLabel.pm lib/PublicInbox/LeiMark.pm diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 9cacb142..fdb0bbcf 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -744,38 +744,6 @@ sub lei_config { x_it($self, $?) if $?; } -sub lei_init { - my ($self, $dir) = @_; - my $cfg = _lei_cfg($self, 1); - my $cur = $cfg->{'leistore.dir'}; - $dir //= store_path($self); - $dir = rel2abs($self, $dir); - my @cur = stat($cur) if defined($cur); - $cur = File::Spec->canonpath($cur // $dir); - my @dir = stat($dir); - my $exists = "# leistore.dir=$cur already initialized" if @dir; - if (@cur) { - if ($cur eq $dir) { - _lei_store($self, 1)->done; - return qerr($self, $exists); - } - - # some folks like symlinks and bind mounts :P - if (@dir && "@cur[1,0]" eq "@dir[1,0]") { - lei_config($self, 'leistore.dir', $dir); - _lei_store($self, 1)->done; - return qerr($self, "$exists (as $cur)"); - } - return fail($self, <<""); -E: leistore.dir=$cur already initialized and it is not $dir - - } - lei_config($self, 'leistore.dir', $dir); - _lei_store($self, 1)->done; - $exists //= "# leistore.dir=$dir newly initialized"; - return qerr($self, $exists); -} - sub lei_daemon_pid { puts shift, $$ } sub lei_daemon_kill { diff --git a/lib/PublicInbox/LeiInit.pm b/lib/PublicInbox/LeiInit.pm new file mode 100644 index 00000000..c6c0c01b --- /dev/null +++ b/lib/PublicInbox/LeiInit.pm @@ -0,0 +1,41 @@ +# Copyright (C) 2021 all contributors +# License: AGPL-3.0+ + +# for the "lei init" command, not sure if it's even needed... +package PublicInbox::LeiInit; +use v5.10.1; +use File::Spec; + +sub lei_init { + my ($self, $dir) = @_; + my $cfg = $self->_lei_cfg(1); + my $cur = $cfg->{'leistore.dir'}; + $dir //= $self->store_path; + $dir = $self->rel2abs($dir); + my @cur = stat($cur) if defined($cur); + $cur = File::Spec->canonpath($cur // $dir); + my @dir = stat($dir); + my $exists = "# leistore.dir=$cur already initialized" if @dir; + if (@cur) { + if ($cur eq $dir) { + $self->_lei_store(1)->done; + return $self->qerr($exists); + } + + # some folks like symlinks and bind mounts :P + if (@dir && "@cur[1,0]" eq "@dir[1,0]") { + $self->lei_config('leistore.dir', $dir); + $self->_lei_store(1)->done; + return $self->qerr("$exists (as $cur)"); + } + return $self->fail(<<""); +E: leistore.dir=$cur already initialized and it is not $dir + + } + $self->lei_config('leistore.dir', $dir); + $self->_lei_store(1)->done; + $exists //= "# leistore.dir=$dir newly initialized"; + $self->qerr($exists); +} + +1;