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;
--
unsubscribe: one-click, see List-Unsubscribe header
archive: https://public-inbox.org/meta/

Reply via email to