user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20210328090124.3541-3-e@80x24.org> (raw)
In-Reply-To: <20210328090124.3541-1-e@80x24.org>

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 <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# 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;

  parent reply	other threads:[~2021-03-28  9:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-28  9:01 [PATCH 00/12] lei blob and some yak-shaving Eric Wong
2021-03-28  9:01 ` [PATCH 01/12] lei: simplify PktOp callers Eric Wong
2021-03-28  9:01 ` Eric Wong [this message]
2021-03-28  9:01 ` [PATCH 03/12] lei blob: dclose if already failed Eric Wong
2021-03-28  9:01 ` [PATCH 04/12] lei blob: support --no-mail switch Eric Wong
2021-03-28  9:01 ` [PATCH 05/12] lei blob: fail early if no git dirs Eric Wong
2021-03-28  9:01 ` [PATCH 06/12] lei blob: some extra tests Eric Wong
2021-03-28  9:01 ` [PATCH 07/12] lei help: show "NAME=VALUE" properly for -c Eric Wong
2021-03-28  9:01 ` [PATCH 08/12] lei blob: flesh out help text Eric Wong
2021-03-28  9:01 ` [PATCH 09/12] t/lei_store: ensure LeiSearch responds to ->isrch Eric Wong
2021-03-28  9:01 ` [PATCH 10/12] lei blob: add remote external support Eric Wong
2021-03-28  9:01 ` [PATCH 11/12] lei: drop coderepo placeholders, submodule TODO Eric Wong
2021-03-28  9:31   ` Eric Wong
2021-03-28  9:01 ` [PATCH 12/12] treewide: shorten temporary filename Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210328090124.3541-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 02/12] lei init: split out into separate file' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git