1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # for the "lei init" command, not sure if it's even needed...
5 package PublicInbox::LeiInit;
10 my ($self, $dir) = @_;
11 my $cfg = $self->_lei_cfg(1);
12 my $cur = $cfg->{'leistore.dir'};
13 $dir //= $self->store_path;
14 $dir = $self->rel2abs($dir);
15 my @cur = stat($cur) if defined($cur);
16 $cur = File::Spec->canonpath($cur // $dir);
18 my $exists = "# leistore.dir=$cur already initialized" if @dir;
21 $self->_lei_store(1)->done;
22 return $self->qerr($exists);
25 # some folks like symlinks and bind mounts :P
26 if (@dir && "@cur[1,0]" eq "@dir[1,0]") {
27 $self->lei_config('leistore.dir', $dir);
28 $self->_lei_store(1)->done;
29 return $self->qerr("$exists (as $cur)");
31 return $self->fail(<<"");
32 E: leistore.dir=$cur already initialized and it is not $dir
35 $self->lei_config('leistore.dir', $dir);
36 $self->_lei_store(1)->done;
37 $exists //= "# leistore.dir=$dir newly initialized";