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 $cfg = $self->_lei_cfg(1);
11 my $cur = $cfg->{'leistore.dir'};
12 $dir //= $self->store_path;
13 $dir = $self->rel2abs($dir);
14 my @cur = stat($cur) if defined($cur);
15 $cur = $self->canonpath_harder($cur // $dir);
17 my $exists = "# leistore.dir=$cur already initialized" if @dir;
20 $self->_lei_store(1)->done;
21 return $self->qerr($exists);
24 # some folks like symlinks and bind mounts :P
25 if (@dir && "@cur[1,0]" eq "@dir[1,0]") {
26 $self->_config('leistore.dir', $dir);
27 $self->_lei_store(1)->done;
28 return $self->qerr("$exists (as $cur)");
30 return $self->fail(<<"");
31 E: leistore.dir=$cur already initialized and it is not $dir
34 $self->_config('leistore.dir', $dir);
35 $self->_lei_store(1)->done;
36 $exists //= "# leistore.dir=$dir newly initialized";