diff options
author | Eric Wong <e@80x24.org> | 2021-03-28 09:01:14 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-03-28 23:01:36 +0000 |
commit | 0084fd94e2354fd0f197e934dd9b8852b044004a (patch) | |
tree | 5bba7e0640cc50984573d8543bcd826012515409 /lib/PublicInbox/LeiInit.pm | |
parent | 954581b8e575966a8bddc35e3b23d81d16a52833 (diff) | |
download | public-inbox-0084fd94e2354fd0f197e934dd9b8852b044004a.tar.gz |
This is a rarely-needed command, so keep it separate file so it's easier-to-find and maybe saves a bit of RAM.
Diffstat (limited to 'lib/PublicInbox/LeiInit.pm')
-rw-r--r-- | lib/PublicInbox/LeiInit.pm | 41 |
1 files changed, 41 insertions, 0 deletions
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; |