From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 29858203BF for ; Mon, 28 Nov 2022 05:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1669613571; bh=UhjxhFNkJG5scd7G3+NgLJ5ohmYl0GsvFsRSkHEGz+Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lEOcKfsgHMoUHII02ckW9cAQUR6w3lTwTZLfz2MRzpxjg3lSMjDEggPtf9cqIKrIO zYxS/XsXcpdPGZg+07/Qx6cDAtRmCLzKAAFDUCzI1fTu5gOZPbuDJqNr7odF5+L9EU j9zvwK6wdprL58ZrF9xZFOIcXiVZa1rQcutcnhOc= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 86/95] lei_mirror: support {symlinks} from manifest Date: Mon, 28 Nov 2022 05:32:23 +0000 Message-Id: <20221128053232.291618-87-e@80x24.org> In-Reply-To: <20221128053232.291618-1-e@80x24.org> References: <20221128053232.291618-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: It's part of grokmirror, and useful for keeping compatibility. We can make use of File::Spec->abs2rel here to ensure our symlinks are relative and the entire mirror can be copied as a whole. --- lib/PublicInbox/LeiMirror.pm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index fc5bc88d..47db9ccd 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -664,6 +664,7 @@ sub up_fp_done { push @{$self->{chg}->{fp_mismatch}}, $self->{-key}; } +# modifies the to-be-written manifest entry, and sets values from it, too sub update_ent { my ($self) = @_; my $key = $self->{-key} // die 'BUG: no -key'; @@ -694,7 +695,26 @@ sub update_ent { } start_cmd($self, $cmd, { 2 => $self->{lei}->{2} }) if $cmd; } - + if (my $symlinks = $self->{-ent}->{symlinks}) { + my $top = File::Spec->rel2abs($self->{dst}); + for my $p (@$symlinks) { + my $ln = "$top/$p"; + $ln =~ tr!/!/!s; + my (undef, $dn, $bn) = File::Spec->splitpath($ln); + File::Path::mkpath($dn); + my $tgt = "$top/$key"; + $tgt = File::Spec->abs2rel($tgt, $dn); + if (lstat($ln)) { + if (-l _) { + next if readlink($ln) eq $tgt; + unlink($ln) or die "unlink($ln): $!"; + } else { + push @{$self->{chg}->{badlink}}, $p; + } + } + symlink($tgt, $ln) or die "symlink($tgt, $ln): $!"; + } + } $new = $self->{-ent}->{owner} // return; $cur = $self->{-local_manifest}->{$key}->{owner} // "\0"; return if $cur eq $new; @@ -1059,6 +1079,10 @@ W: The above fingerprints may never match without --prune EOM } dump_manifest($m => $ft) if delete($self->{chg}->{manifest}) || $mis; + my $bad = delete $self->{chg}->{badlink}; + warn(<